Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How can I read records from a table in a database and represent it in a hash?

by cwest (Friar)
on Oct 12, 2000 at 21:16 UTC ( [id://36442]=note: print w/replies, xml ) Need Help??


in reply to How can I read records from a table in a database and represent it in a hash?

while your description makes _no_ sense, I will try to explain.

Most literally, you can't. Try an array of hash refs:

my $sth = $dbh->prepare(<<__SQL__); SELECT * FROM $table; __SQL__ $sth->execute; my $table_data = []; push @{$table_data}, $_ while $sth->fetchrow_hashref; $sth->finish;
On the other hand, if you have an id column ( eg. primary key ), you could easily make it ( or any other column, for that matter ) a key in a Hash of Hashes:
my $sth = $dbh->prepare(<<__SQL__); SELECT * FROM $table; __SQL__ $sth->execute; my $table_data = {}; $table_data->{$_->{id}} = $_ while $sth->fetchrow_hashref; $sth->finish;
Enjoy!
--
Casey
    I am a Superhero.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found