in reply to HTML table with HTML::Template and loop in a loop

Thanks everyone for your help,

using blokhead's first reply, I typed the following data structure, and passed it 'raw' to HTML::Template.
%loop_data = ( rows => [ { cells => [ { data => 'one'}, { data => 'ein'}, ], }, { cells => [ { data => 'two'}, { data => 'zwei'}, ], }, { cells => [ { data => 'three'}, { data => 'drei'}, ], }, ], );
Being able to see this raw data structure helped me to figure out how to create it programatically for HTML::Template.

I was now able to see how cfeaks's "foreach" example worked.

then... thanks to jeffa's replies and his Map: The Basics tutorial, I was able to figure out what the map statements were doing.

Using this new-found knowledge, I was able to write this new script which uses an array '@columns' to 1/, fill one loop (the first table row) with values, and 2/ create the rest of the table by filling a loop-within-a-loop with data from a database.
#!/usr/bin/perl -wT use strict; use CGI; use DBI; use HTML::Template; use vars qw/ $q $dbh $sth $rv $rc $template $html @columns @headings_data @rows_data $sql / +; @columns = qw/ prod_code dep_1 dep_2 dep_3 /; @headings_data = map {{ cell_data => $_ }} @columns; $sql = 'SELECT ' . join(', ', @columns) . ' FROM products WHERE dep_1= +01'; $dbh = DBI->connect("dbi:mysql:database:host", "user", "pass") or print_error("Could not connect to Database", $DBI::errstr); $sth = $dbh->prepare( $sql ) or die("Couldn't prepare the database", "$DBI::errstr"); $rv = $sth->execute(@_) or die("Couldn't execute database", "$DBI::errstr"); while ( my @data = $sth->fetchrow_array ) { my @cells = map {{ cell_data => $_ }} @data; push @rows_data, { cells => \@cells }; } $html = do { local $/; <DATA> }; $template = HTML::Template->new(scalarref => \$html); $template->param( headings => \@headings_data, rows => \@rows_data ); $q = new CGI; print $q->header; print $template->output; $dbh->disconnect; exit; __DATA__ <html> <body> <table> <tr> <!-- TMPL_LOOP NAME=headings --> <td><!-- TMPL_VAR NAME=cell_data --></td> <!-- /TMPL_LOOP --> </tr> <!-- TMPL_LOOP NAME=rows --> <tr> <!-- TMPL_LOOP NAME=cells --> <td><!-- TMPL_VAR NAME=cell_data --></td> <!-- /TMPL_LOOP --> </tr> <!-- /TMPL_LOOP --> </table> </body> </html>
The original data I posted was not in the format I was actually working with, but I presented it as such to enable me to figure out exactly what HTML::Template wanted, and how to create that myself (rather that using another-monks map-statement-on-a-plate that I couldn't understand).
A big thankyou to everyone for having the patience to help me past another milestone of Perl understanding!