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

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;
I'd be grateful If someone could help me to get this right.

In reply to Making a hash of making a hash of an array by jonnyfolk

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.