Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: How to add MySql Records To Array or Hash?

by McA (Priest)
on Sep 09, 2013 at 18:45 UTC ( #1053070=note: print w/replies, xml ) Need Help??

in reply to How to add MySql Records To Array or Hash?


the decision whether to use arrays of hashes depends on the size of the result set and other aspects (e.g. maintainability). Hashes and access by field names makes it IMHO more readable.

I would propose the following structure:

my %hash = ( 12345 => { id => 12345, position => 'QB', salary => 15000, points => 20, }, 54321 => { id => 54321, position => 'QB', salary => 14500, points => 19, }, );

To get this structure from a database via DBI have a look at


Replies are listed 'Best First'.
Re^2: How to add MySql Records To Array or Hash?
by jdlev (Scribe) on Sep 09, 2013 at 20:58 UTC
    That looks a lot like what I'm looking for. It says in the DBI documentation that the $key_fields should be called as an array if you want to call multiple columns. Any idea on how to do that? I haven't been able to find any example :(

    I love it when a program comes together - jdhannibal

      You don't need it IMHO as you have ID as primary key, so just set $key_fields to the field name 'ID'.

      One thing you have to be aware of is the case of the identifier. Look at NAME_uc and NAME_lc in the DBI documentation.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1053070]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2018-06-25 12:24 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.