Perl Newby has asked for the wisdom of the Perl Monks concerning the following question:
This is the code that I have written so far:24|St. Louis Cardinals 1|4995|Fernando Vina|2B|4|0|0|0|0|0|0|.317|.397|.425 2|5602|Edgar Renteria|SS|4|0|1|0|1|0|1|.260|.321|.470 3|5151|Jim Edmonds|CF|3|1|2|1|5|1|0|.409|.538|.864 4|3866|Mark McGwire|1B|3|1|1|1|4|1|0|.323|.494|.903 5|4547|Ray Lankford|LF|4|0|0|0|0|0|3|.193|.297|.420 6|5046|Craig Paquette|3B|3|0|1|0|2|1|1|.264|.325|.486 7|6117|J.D. Drew|RF|4|0|1|0|1|0|1|.327|.462|.596 8|5205|Mike Matheny|C|3|0|0|0|0|0|0|.289|.375|.421 8|4506|Thomas Howard|PH|1|0|1|0|1|0|0|.280|.357|.760 8|5897|Eli Marrero|PR|0|0|0|0|0|0|0|.250|.343|.643 9|4379|Andy Benes|P|2|0|0|0|0|0|0|.167|.167|.167 9|3625|Eric Davis|PH|1|0|0|0|0|0|1|.281|.388|.491 9|4625|Heathcliff Slocumb|P|0|0|0|0|0|0|0|.000|.000|.000 9|4979|Mike Mohler|P|0|0|0|0|0|0|0|1.000|1.000|1.000 9|5880|Larry Sutton|PH|1|0|0|0|0|0|0|.000|.000|.000 TOTALS|33|2|7|2|14|3|7 17|Cincinnati Reds 1|5746|Pokey Reese|2B|3|1|1|1|1|0|0|.343|.408|.429 2|5930|Sean Casey|1B|3|0|1|0|1|1|0|.200|.344|.320 3|4305|Ken Griffey Jr.|CF|4|1|2|2|5|0|1|.210|.326|.448 4|5699|Dmitri Young|LF|4|0|1|0|1|0|1|.287|.339|.446 4|5540|Alex Ochoa|LF|0|0|0|0|0|0|0|.297|.357|.595 5|4615|Eddie Taubensee|C|4|0|0|0|0|0|1|.325|.387|.542 6|4159|Dante Bichette|RF|3|0|2|0|2|0|0|.219|.265|.324 6|6174|Scott Williamson|P|0|0|0|0|0|0|0|-|-|- 7|5838|Aaron Boone|3B|3|0|0|0|0|0|0|.270|.389|.438 8|5508|Juan Castro|SS|3|1|1|0|2|0|0|.333|.333|.667 9|5346|Ron Villone|P|1|0|0|0|0|0|0|.222|.222|.222 9|5299|Michael Tucker|RF|0|0|0|0|0|0|0|.167|.375|.500 TOTALS|28|3|8|3|12|1|3
open(INPUT,"c:/MLB_boxscore.TXT") or die "Can't open file"; print "<html><head><title>Box Score</title></head><body>"; print "<table>"; use strict; my $insection = ""; $y = 1; $l = 0; $/ = ""; $players1 = <INPUT>; $totals1 = <INPUT>; $players2 = <INPUT>; $totals2 = <INPUT>; $players = $players1; $totals = $totals1; players($players); totals($totals); print "\n\n"; $players = $players2; $totals = $totals2; players($players); totals($totals); print "</table></body></html>"; close INPUT; sub chomped{ $/ = "\n"; chomp; @LS = (); push @LS, split('\n',$player); return @LS; } sub players{ $players = $players; print "<table>"; foreach $player($players){ chomped($player); foreach $LS(@LS){ chomp; @SL = (); push @SL, split('\|',$LS); for ($x=0;$x<=$#SL;$x++){ if ($x == 0){ $id = $SL[$x]; if ($id == $oldid){ print "<tr><td width='150'>_"; } else { print "<tr><td width='150'>"; } $oldid = $id; } elsif ($x == 1){ next; } elsif ($x == 2){ print $SL[$x]; } elsif ($x == 3){ print ", " . $SL[$x] . "</td>"; } elsif ($x == 13){ print "<td width='20'>" . $SL[$x] . "</td></tr>"; } else { print "<td width='20'>" . $SL[$x] . "</td>"; } } } } } sub totals{ $totals = $totals; foreach $total($totals){ chomp; @LS = (); push @LS, split('\|',$total); print "<tr>"; print "<td>" . $LS[$_] . "</td>" for(0..$#LS); print "<td align='center'>-</td>" for(0..2); print "</tr></table>"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Running a Sub from a Text File 2
by buckaduck (Chaplain) on Apr 20, 2001 at 02:25 UTC | |
|
Re: Running a Sub from a Text File 2
by plazm (Initiate) on Apr 20, 2001 at 00:35 UTC |