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 $/;}; 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__
Item Quantity Description Price