Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: DBI and HTML::Template

by chipmunk (Parson)
on Nov 22, 2001 at 10:04 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://126944]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-03-28 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found