http://www.perlmonks.org?node_id=126939


in reply to DBI and HTML::Template

HTML::Template->param expects an array reference of hash references. So you would need to create a structure like this
$myarrayref = [ { NAME => 'Bob' , JOB => 'Programmer'} , { NAME => 'Bill' , JOB => 'Manager'} , ];
and use it like this.
$template->param( EMPLOYEE_INFO => $myarrayref);
To do this using DBI you would want to do something like the following. First fetch each row as a hash reference then push each one of these onto a array reference. Note: you will need to dereference the array reference hence the @$myarrayref.
# Create statement handle $sth = $dbh->prepare($somesql); # execute statement handle $sth->execute(); # loop through rows while ($hashref = $sth->fethrow_hashref()) { push @$myarrayref , $hashref; } # clean up statement handle $sth->finish();
Once you have the array reference of hash references you can pass this to the param method of HTML::Template like so.
$template->param(EMPLOYEE_INFO => $myarrayref);