Ok, in a nutshell, I'm trying to convert this:
(which works exactly as I want)my $hash_ref; while ( my $row = $sth->fetchrow_hashref ) { push @{ $hash_ref->{ $row->{ 'msgid' } } }, { 'option' => $row->{ 'option' }, 'option_data' => $row->{ 'option_data' } }; }
To this:
(which doesn't work, but iterates everything in < 10 seconds as opposed to the other way which is around 150 seconds to iterate all the rows.)my $rows = $sth->fetchall_arrayref; my %hash = map { $_->[0] => { 'option' => $_->[1], 'option_data' => $_->[2] }; } @{$rows};
| id | option | option_data |
| 1234 | foo | fooval |
| 1235 | bar | barval |
| 1236 | baz | bazval |
| 1234 | quux | quuxval |
So, like the results of the while loop, I'd like the map to end up with this:
'1234' => [ { 'option_data' => 'fooval', 'option' => 'foo' }, { 'option_data' => 'quuxval', 'option' => 'quux' } ], '1235' => [ { 'option_data' => 'barval', 'option' => 'bar' } ], '1236' => [ { 'option_data' => 'bazval', 'option' => 'baz' } ]
--
"A long habit of not thinking a thing wrong, gives it a superficial appearance of being right." -- Thomas Paine
naChoZ
In reply to while/push to map, data structure confusion by naChoZ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |