Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by wazat (Monk)
on Aug 18, 2020 at 00:04 UTC ( [id://11120859]=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

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";
  • Comment on Re: storing values of hash of hashes in an array based on numerical order of second key
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-18 07:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found