Whether or not HMTL::Template is a better choice than CGI.pm
is really up to you, but definetly look into CSS! In the
meantime, here is a watered down version of your problem
that uses HTML::Template instead (be sure and check out
our HTML::Template Tutorial for some lessons on the basics).
use strict;
use CGI qw(header);
use HTML::Template;
my $cart_ref = {
42 => {
qty => 5,
price => 5,
description => 'widget 42',
},
77 => {
qty => 2,
price => 7,
description => 'widget 77',
},
};
my $html = do {local $/;<DATA>};
my $tmpl = HTML::Template->new(scalarref=> \$html);
my $rows = [
map {
{ id => $_, %{$cart_ref->{$_}} }
} keys %$cart_ref
];
$tmpl->param(rows => $rows);
print header, $tmpl->output;
__DATA__
<table>
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Description</th>
<th>Price</th>
</tr>
<tmpl_loop rows>
<tr>
<td><tmpl_var id></td>
<td><tmpl_var qty></td>
<td><tmpl_var description></td>
<td><tmpl_var price></td>
</tr>
</tmpl_loop>
</table>
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)
|