#! /bin/perl

main();

sub main
{
    print "\n\nFile to check: ";
    local $fname = <STDIN>;

    LoopChk1();
}


sub LoopChk1()
{
    print "\nIgnore length of (# of lines or blank): ";
    my $iglen = <STDIN>;
    chomp($iglen);
    my @linecnt;

    print "\noutput file or blank: ";
    my $outpf = <STDIN>;
    chomp($outpf);

    die unless open(DATA, "$fname");
    if ($outpf) {
	die unless open(OUTP, ">>$outpf");
    }
    
    my ($line, $topval, $count);
    while ($line = <DATA>) {
	next if ($line !~ /(\d+)/);
	$topval = $1;
	$line = <DATA>; # skip "-------------";
        for ($count = 0; (($line = <DATA>) =~ /\d+/); $count++) {;}
	if ($iglen) {
	    print("\n$topval : $count\n") if ($count != $iglen);
	}
	if ($outpf) {
	    print(OUTP "\n$topval : $count\n") if ($count != $iglen);
	}
	$linecnt[$count]++;
    }

    print "\n";
    my $i;
    for ($i = 1; $i <= 20; $i++) {
	print("There are " . $linecnt[$i] . " loops of $i.\n");
    }
}
