Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Sorting a hash of hashes

by diddy_perl (Novice)
on May 15, 2012 at 08:42 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://970582]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2024-04-23 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found