jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:
In order to populate a table in HTML::Template I'm having to go a bit beyond my current knowledge base and have run into some problems.
I have set up and confirmed the template using the example having entered the values into the script. I cannot, however, extract the values from a file to populate the hash. In the code that follows I am opening a flat file and reversing the line order of the file to extract the last 10 records
I'd be grateful If someone could help me to get this right.open (FILE, "$record") or die "can't open $record: $!"; my @record = reverse <FILE>; close FILE; foreach my $line (@record) { ($timestamp, $current_time, $funds, $action, $current_funds) = split " +\t",$line; while ($count < 10){ $member{$timestamp} = [$current_time, $funds, $action, $current_fu +nds]; $count += 1; } } %member = ( $timestamp => [$current_time, $funds, $action, $current_fu +nds]); my $template = HTML::Template->new(filename => 'temp_late.html'); my @loop; # the loop data will be put in here # fill in the loop, sorted by timestamp foreach my $timestamp (sort keys %member) { # get the other data from the data hash my ($current_time, $funds, $action, $current_funds) = @{$member{$t +imestamp}}; # make a new row for this data - the keys are <TMPL_VAR> names # and the values are the values to fill in the template. my %row = ( date => $current_time, amount => $funds, action => $action, total => $current_funds, ); # put this row into the loop by reference push(@loop, \%row); } # call param to fill in the loop with the loop data by reference +. $template->param(member => \@loop); # send the obligatory Content-Type print "Content-Type: text/html\n\n"; # print the template print $template->output;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Making a hash of making a hash of an array
by kabel (Chaplain) on Jun 04, 2003 at 04:58 UTC | |
by jonnyfolk (Vicar) on Jun 04, 2003 at 05:24 UTC | |
|
(jeffa) Re: Making a hash of making a hash of an array
by jeffa (Bishop) on Jun 04, 2003 at 05:55 UTC | |
|
Re: Making a hash of making a hash of an array
by pzbagel (Chaplain) on Jun 04, 2003 at 05:06 UTC | |
by jonnyfolk (Vicar) on Jun 04, 2003 at 05:33 UTC | |
by pzbagel (Chaplain) on Jun 04, 2003 at 07:16 UTC | |
by jonnyfolk (Vicar) on Jun 04, 2003 at 10:52 UTC | |
by jeffa (Bishop) on Jun 04, 2003 at 14:01 UTC |