in reply to while/push to map, data structure confusion

Notwithstanding the fine answer you've already received, if you still want to do it with a fetchall, you can't build the hash with map (okay, you probably can, but not in a conventional way) because you're not building a straightforward hash, where each input element corresponds to a hash member. Instead, you're building a compound hash where each input element gets pushed onto a hash member.

This example code does the transformation you want.

#!perl use Data::Dumper; $rows = [[qw(1234 foo fooval)],[qw(1235 bar barval)],[qw(1234 quux quu +xval)]]; my %hash; for (@$rows) { push @{$hash{$_->[0]}} , { option => $_->[1] , option_data => $_->[2] } ; } print Dumper(\%hash);
Update: which, of course, looks very similar to dragonchild's solution, because it's doing basically the same thing.

We're not really tightening our belts, it just feels that way because we're getting fatter.