Perl Newby has asked for the wisdom of the Perl Monks concerning the following question:

I am using the sub at the bottom to pull data out of a Text File chunk by chunk. For example,
DOUBLES 5046|Craig Paquette|24|St. Louis Cardinals|1|5 5508|Juan Castro|17|Cincinnati Reds|1|1 HOME RUNS 5151|Jim Edmonds|24|St. Louis Cardinals|1|11 3866|Mark McGwire|24|St. Louis Cardinals|1|11 4305|Ken Griffey Jr.|17|Cincinnati Reds|1|8
There are more fields in the text file. The above is just two of the fields. I need the sub to be able to go through each line until it reaches a blank space. The sub would only do Doubles or Home Runs. So, if I were trying to pull out Doubles, after the sub was run, it would stop at the whitespace after Doubles. At that point the sub should end. As is, the sub will only go through one line of data before ending. Any suggestions?
#Our Sub sub score { if(defined($oldsection) && $insection ne $oldsection) { undef $oldsection; } elsif (defined($oldsection) && $insection eq $oldsection) { if ($insection ne "pitching") { last if /^([A-Z][A-Z\s]*)/; chomp; @LS = (); push @LS, split('\|',$_); print "<tr>"; print "<td>" . $LS[$_] . "</td>" for (1..$#LS); print "</tr>"; } } elsif ($insection && !defined($oldsection)) { $oldsection = $insection; next; } $insection = ""; }

Replies are listed 'Best First'.
Re: Looping Through a Sub
by ton (Friar) on Apr 14, 2001 at 03:00 UTC
    Where's the loop?
    -----
    Be bloody, bold, and resolute; laugh to scorn
    The power of man...