in reply to Running a Sub from a Text File 2

Here's some suggestions, which utilize CGI and HTML::Table for clarity. Some simplification was possible since leading/trailing whitespace won't matter in an HTML document anyway:
use strict; use CGI ':standard'; use HTML::Table; # I like this module for simple tables open(INPUT,"stats.txt") or die "Can't open file"; print start_html('Box Score'); $/ = ""; # Read data a paragraph at a time while (my $players = <INPUT>) { WritePlayers($players); # Grab all chunks of data in a loop! my $totals = <INPUT>; WriteTotals($totals); } close INPUT; sub WritePlayers { # Renamed for clarity my $table = HTML::Table->new; my $old_id = ''; # Split the chunk into lines and loop foreach my $player (split(/\n/,$_[0])) { # Split the line into fields my ($id, undef, $name, $pos, @others) = split(/\|/, $player); # Add the data to my HTML table my $prefix = ($id eq $old_id) ? '_' : ''; $table->addRow("$prefix$name, $pos", @others); $old_id = $id; } # Table formatting $table->setColWidth(1, 150); $table->setColWidth($_, 20) foreach (2..11); $table->print; print p; } sub WriteTotals { # Renamed for clarity my $table = HTML::Table->new; # Just split this small chunk into fields my @fields = split(/\|/, $_[0]); # Add the fields to my HTML table $table->addRow(@fields); # Table formatting $table->setColAlign($_, 'CENTER') foreach (1..3); $table->print; print p; }

Note that you can easily turn this into a CGI program by adding print header; before the print start_html(); line.

buckaduck