Perl hash of arrays column name as keys -
i trying create hash of arrays using result of sql query: eg.
column1:
1 2 3 4
column2:
a b c d
desired result:
my %by_col = ( 'column1'=>['1','2','3','4'], 'column2'=>['a','b','c','d'], );
i able result array of hashes using:
while ($hash_ref = $sth->fetchrow_hashref()) { force @$hash_array_ref, { %$hash_ref }; }
but can't figure out other way round.
thanks!
while (my $row = $sth->fetchrow_hashref()) { $col_name (keys(%$row)) { force @{ $by_col{$col_name} }, $row->{$col_name}; } }
arrays perl hash
No comments:
Post a Comment