record.txt is a tab delimited file similar this one that i used for testing:use strict; use warnings; use Tie::File; use Data::Dumper; use HTML::Template; # part 1: get the last ten lines and store in a 2-D array my @record; tie @record, 'Tie::File', 'record.txt' or die $!; my @last10 = map [split "\t"], @record[map -$_,1..10]; #print STDERR Dumper \@last10; # part 2: create a list of hashes (LoH) for HTML::Template my %hash; my @headers = qw(date amount action total); my @loop = map { @hash{@headers} = @$_[1..@$_]; # exclude timestamp $_ = {%hash} } sort {$a->[0] <=> $b->[0]} @last10; # sort by timestamp #print STDERR Dumper \@loop; # part 3: shove data through template my $tmpl = HTML::Template->new(filehandle => \*DATA); $tmpl->param(member => \@loop); print $tmpl->output; __DATA__ <table> <tr> <th>Date</th> <th>Amount</th> <th>Action</th> <th>Total</th> </tr> <tmpl_loop member> <tr> <td><tmpl_var date></td> <td><tmpl_var amount></td> <td><tmpl_var action></td> <td><tmpl_var total></td> </tr> </tmpl_loop> </table>
1054703890 a b c d 1054703892 e f g h 1054703894 1 2 3 4 1054703896 5 6 7 8 1054703891 A B C D 1054703893 E F G H 1054703895 my how time flies
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to (jeffa) Re: Making a hash of making a hash of an array
by jeffa
in thread Making a hash of making a hash of an array
by jonnyfolk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |