Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Sorting a hash of hashes

by diddy_perl (Novice)
on May 15, 2012 at 08:42 UTC ( #970582=note: print w/replies, xml ) Need Help??


in reply to Sorting a hash of hashes

Try this

## Fort test1 ## sort in descending order by value1, select first @values1 = map { $_, $HoH{$_}{'Test1'}{'value1'} } sort { $HoH{$b}{'Test1'}{'value1'} <=> $HoH{$a}{'Test1'}{'value1'} + } keys %HoH; ## sort in descending order by value2, select first @values2 = map { $_, $HoH{$_}{'Test1'}{'value2'} } sort { $HoH{$b}{'Test1'}{'value2'} <=> $HoH{$a}{'Test1'}{'value2'} + } keys %HoH; print "Fort Test1\n"; print " ", $values1[0], " has value1=", $values1[1], "\n"; print " ", $values2[0], " has value2=", $values2[1], "\n"; ## For test2 ## sort in descending order by value1, select first @values1 = map { $_, $HoH{$_}{'Test2'}{'value1'} } sort { $HoH{$b}{'Test2'}{'value1'} <=> $HoH{$a}{'Test2'}{'value1'} + } keys %HoH; ## sort in descending order by value2, select first @values2 = map { $_, $HoH{$_}{'Test2'}{'value2'} } sort { $HoH{$b}{'Test2'}{'value2'} <=> $HoH{$a}{'Test2'}{'value2'} + } keys %HoH; print "Fort Test2\n"; print " ", $values1[0], " has value1=", $values1[1], "\n"; print " ", $values2[0], " has value2=", $values2[1], "\n";

Enjoy!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://970582]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-02-18 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (250 votes). Check out past polls.

    Notices?