I like Bill's reply
here is another way. I'm assuming there are no collisions among the 2nd level keys. I also assume that the 2nd level keys are non-negative integers and are not large numbers. I also note that you don't use the 1st level keys.
use strict; use warnings; my $VAR1 = { '315' => {'8' => 0}, '329' => {'6' => 0}, '352' => {'5' => 0}, '390' => {'1' => 0}, '280' => {'7' => 1}, '360' => {'9' => 0}, '349' => {'4' => 0}, '305' => {'10' => 0}, '380' => {'3' => 1}, '251' => {'2' => 0} }; my @a; for my $x (values %$VAR1 ) { for my $y ( keys %$x ) { $a[$y] = [$y, $x->{$y}]; } } print join("\t", ( map { $_->[0]; } grep { defined } @a ) ), "\n"; print join("\t", ( map { $_->[1]; } grep { defined } @a ) ), "\n";
In reply to Re: storing values of hash of hashes in an array based on numerical order of second key
by wazat
in thread storing values of hash of hashes in an array based on numerical order of second key
by v15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |