Discard the "pos" part of %pos2base2bin, sort the keys of %base2bin, print those on the first line and print a hash slice on the second.
use 5.026; use warnings; my %pos2base2bin = ( '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 %base2bin = map { %{ $_ } } values %pos2base2bin; my @order = sort { $a <=> $b } keys %base2bin; say qq{sample\t}, join qq{\t}, @order; say qq{file1\t}, join qq{\t}, @base2bin{ @order };
Produces:-
sample 1 2 3 4 5 6 7 8 + 9 10 file1 0 0 1 0 0 0 1 0 + 0 0
I hope this is of interest.
Cheers,
JohnGG
In reply to Re: storing values of hash of hashes in an array based on numerical order of second key
by johngg
in thread storing values of hash of hashes in an array based on numerical order of second key
by v15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |