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 = ""; }

In reply to Looping Through a Sub by Perl Newby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.