http://www.perlmonks.org?node_id=1053070


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

Hi,

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 http://search.cpan.org/dist/DBI/DBI.pm#selectall_hashref.

Regards
McA