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)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.