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?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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |