Check out
(jeffa) Re: Structure for nested html::template loops.
UPDATE:
Here is how i would do it ... this is almost identical
to blokhead's answer:
use strict;
use HTML::Template;
my $html = do{local $/;<DATA>};
my %hash = map { $_ => chr $_ } (97..122);
my ($i,$j) = (0,0);
my $max = 5;
my $table;
for (sort keys %hash) {
push @{$table->[$j]->{key}},{key => $_};
push @{$table->[$j]->{val}},{val => $hash{$_}};
$j++ unless ++$i % $max;
}
my $tmpl = HTML::Template->new(
scalarref => \$html,
);
$tmpl->param(
table => $table
);
print $tmpl->output;
__DATA__
<style type="text/css">
<!--
table { border-style: outset; border-width: thin; }
th { border-style: inset; }
td { border-style: inset; }
-->
</style>
<tmpl_loop table>
<table border="1">
<tr>
<th>Key</th>
<tmpl_loop key>
<td><tmpl_var key></td>
</tmpl_loop>
</tr>
<tr>
<th>Val</th>
<tmpl_loop val>
<td><tmpl_var val></td>
</tmpl_loop>
</tr>
<table>
</tmpl_loop>
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)