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


in reply to Re: DBI and HTML::Template
in thread DBI and HTML::Template

# loop through rows while ($hashref = $sth->fethrow_hashref()) { push @$myarrayref , $hashref; }
Be aware that the documentation for DBI specifically forbids using fetchrow_hashref in that way:
Currently, a new hash reference is returned for each row. This will change in the future to return the same hash ref each time, so don't rely on the current behaviour.
Although your code will work with existing versions of DBI, in some future version it will break with every reference in the array pointing to the same hash, containing the last row fetched. Instead, you should make sure to create a new hash for each row:
# loop through rows while ($hashref = $sth->fetchrow_hashref()) { push @$myarrayref , { %$hashref }; }
There's also fetchall_arrayref, as lachoy explained.