Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: storing values of hash of hashes in an array based on numerical order of second key

by johngg (Canon)
on Aug 18, 2020 at 14:30 UTC ( [id://11120879]=note: print w/replies, xml ) Need Help??


in reply to storing values of hash of hashes in an array based on numerical order of second key

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

  • Comment on Re: storing values of hash of hashes in an array based on numerical order of second key
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11120879]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2024-04-25 19:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found