I'm trying to learn more and more about how I can use HTML::Template to optimize what I've previously done "statically" with CGI.pm.
Here's a place where I'm currently snagged:
my $snapdir = "/some/path/to/snapshots";
my @iso = ('ca', 'zh_CN', 'cs', 'da', 'en', 'fo', 'fr',
'de', 'it', 'ja', 'no', 'pl', 'ru', 'es',
'th', 'tr');
my @lang = ('Catalan', 'Chinese', 'Czech', 'Danish', 'English',
'Faroese', 'French', 'German', 'Italian', 'Japanese',
'Norwegian', 'Polish', 'Russian', 'Spanish', 'Thai', 'Turk
+ish');
my @languages;
push @languages, {
name => $lang[$_],
iso => $iso[$_],
file => "viewer_$iso[$_].prc",
}, foreach (0..$#iso);
print '<table border="1">';
print '<th>Language</th>';
print '<th>Last updated</th>';
foreach (0..$#iso) {
my $string = shift;
my $viewer = {
name => $lang[$_],
iso => $iso[$_]};
my $ppi = {
name => $lang[$_],
iso => $iso[$_]};
$viewer->{file} = "$root/viewer_$iso[$_].prc";
$ppi->{file} = "$root/ppi_$iso[$_].prc";
next unless stat($viewer->{file});
$viewer->{size} = (CORE::stat($viewer->{file}))[7];
$ppi->{size} = (CORE::stat($ppi->{file}))[7];
$viewer->{time} = (CORE::stat($viewer->{file}))[9];
$ppi->{time} = (CORE::stat($ppi->{file}))[9];
$languages[$_] = $viewer;
my $name = sprintf("%-12s", $viewer->{'name'});
my $filedate = strftime "%D %r", localtime $viewer->{'time'
+};
my $filesize = insert_commas($viewer->{'size'});
my $ppisize = insert_commas($ppi->{size});
print "<tr>";
print "<td align=\"right\">"
. $cgi->a({-href=>substr("$snapdir/$viewer->{'file'}", 3
+5),
-title=>"$filesize bytes"}, "$name")
. "(" . $cgi->a({-href=>substr("$snapdir/$ppi->{'file'}"
+, 34),
-title=>"$ppisize bytes"}, "ppi") . ")" . "</td>";
print "<td>$filedate</td>";
print "</tr>";
}
print "</table>";
print $cgi->end_div();
What is the easiest way to convert this construct into something that HTML::Template, via TMPL_LOOP, can grok?