velocitymodel has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
My code does not execute at all when I try to run it. I used a dummy variable to see where my code was getting caught up at. My last for loop within my subroutine events seems to be stuck in an infinity loop. When debugging my code I am told I am missing right curly brackets as various lines starting from line 2 and 4. I would appreciate advice on how to properly exit my loop and why perl debugger is telling me I am missing all these right curly brackets.
Thanks
use strict; use warnings; my $fin = "SELECTDAT2"; my $fout = "myfile"; open my $ih, '<', $fin or die "cannot open $fin for reading, $! "; open my $oh, '>', $fout or die "cannot open $fout for writing, $! "; my @records; my @list; my @sorted_recs; while (<$ih>) { chomp; my @tokens = split; my $SEC1 = $tokens[3]; my $LAT = $tokens[4]; my $LONG = $tokens[5]; my $DEPTH = $tokens[6]; my $NO = $tokens[10]; my $GAP = $tokens[11]; sub records { my ($SEC1, $LAT, $LONG, $DEPTH, $NO, $GAP) = @records; push @records, [ $SEC1, $LAT, $LONG, $DEPTH, $NO, $GAP ]; #sort by LONG (index 0=NO, 1=SEC1, 2=LONG, 3=LAT, 4=DEPTH, 5=GAP) my $records = \@records; my @sorted_recs = sort { $$records[$a][6] <=> $$records [$b][6] } @rec +ords; return @records; } my $nextline = <$ih>; my $y = $tokens[0], my $m = $tokens[1], my $d = $tokens[2], my $h = $t +okens[3]; sub events { my (@list); my $nextline = <$ih>; foreach $nextline (@list) { my @tokens = split; my $SOURCE = $tokens[0]; my $PSEC = $tokens[3]; my $PQ = $tokens[4]; my $SSEC = $tokens[7]; my $SQ = $tokens[8]; push @list, [ $SOURCE, $PSEC, $PQ, $SSEC, $SQ]; last if $nextline =~/^\s*$/; } return @list; last; } print $oh events(@list), @sorted_recs, "\n"; } close ($oh); close ($ih);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: exiting a for loop
by GrandFather (Saint) on Mar 24, 2011 at 06:42 UTC | |
by velocitymodel (Acolyte) on Mar 24, 2011 at 15:14 UTC | |
|
Re: exiting a for loop
by davido (Cardinal) on Mar 24, 2011 at 06:28 UTC | |
by davido (Cardinal) on Mar 24, 2011 at 07:02 UTC | |
by velocitymodel (Acolyte) on Mar 24, 2011 at 14:46 UTC |