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


in reply to Outputing data from mySQL query into format for use with HTML::Template

A great way to do what you want is built right into DBI, there is no need for extra code to build the data structure:

my %attr = ( dbi_fetchall_arrayref_attr => {}, ); my $statement = q{ SELECT * FROM table WHERE field LIKE ? }; $template->param( rows => $dbh->selectall_arrayref($statement, \%attr, $value), );

This uses a little known, and undocumented feature in DBI, where selectall_arrayref() can be coerced into returning a reference to an array of hash references. This is done through the use of the \%attr hash reference passed to selectall_arrayref().