Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
There's more than one way to do things
 
PerlMonks  

Re: building a hash from a database

by Codon (Friar)
on May 02, 2006 at 16:10 UTC ( #546941=note: print w/ replies, xml ) Need Help??


in reply to building a hash from a database

How big of a CSV are we looking at here? If you have the memory, you could simplify with $sth->fetchall_arrarref({}) which would give you something like this:

$VAR1 = [ { 'id' => 1, 'fname' => 'John', 'lname' => 'Smith', }, { 'id' => 2, 'fname' => 'Sally', 'lname' => 'Smith', }, ];
Then with your friend map, you can massage this structure thusly:
my %hash = map { $_->{'id'} => $_ } @$data;
which would result in something along the lines of
$VAR2 = { '1' => { 'id' => 1, 'fname' => 'John', 'lname' => 'Smith', }, '2' => { 'id' => 2, 'fname' => 'Sally', 'lname' => 'Smith', }, };

Ivan Heffner
Sr. Software Engineer, DAS Lead
WhitePages.com, Inc.


Comment on Re: building a hash from a database
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-04-17 11:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (446 votes), past polls