Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: DBI and HTML::Template

by chipmunk (Parson)
on Nov 22, 2001 at 10:04 UTC ( #126944=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://126944]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-01-24 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?