I have a text file that is similar to this:
SAC BUNTS 5346|Ron Villone|17|Cincinnati Reds|1 SAC FLIES 5746|Pokey Reese|17|Cincinnati Reds|1 STOLEN BASES 4159|Dante Bichette|17|Cincinnati Reds|1|2 CAUGHT STEALING 5602|Edgar Renteria|24|St. Louis Cardinals|1|3 PITCHING 24|St. Louis Cardinals 4379|Andy Benes|L, 2-2|0|6|8|3|3|0|0|1|24|31|41|72|4.41|.258 4625|Heathcliff Slocumb|0|0|1|0|0|0|0|0|0|4|3|8|11|4.08|.231 4979|Mike Mohler|0|0|1|0|0|0|1|3|0|4|8|9|17|8.79|.293
I am trying to use the following code to pull out everything from the file except the PITCHING information. I have been unable to get all of the information I need. Any suggestions?
open(INPUT,"c:/MLB_boxscore.TXT") or die "Can't open file"; print "<html><head><title>My page</title></head><body>"; print "<table>"; my $insection = ""; while (<INPUT>) { if (/^SAC\s+BUNTS/) { $insection="sac bunts" } if (/^SAC\s+FLIES/) { $insection="sac flies" } if (/^STOLEN\s+BASES/) { $insection="stolen bases" } if (/^CAUGHT\s+STEALING) { $insection="caught stealing" } if (/^PITCHING/) { $insection="pitching" } if(defined($oldsection) && $insection ne $oldsection) { undef $oldsection; } elsif (defined($oldsection) && $insection eq $oldsection) { if ($insection == "scoring position"){ 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; } } print "</table></body></html>"; close INPUT;

In reply to Pulling Values out of a File by Anonymous Monk

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.