Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Sorting HOH

by ihb (Deacon)
on May 02, 2005 at 15:18 UTC ( #453281=note: print w/replies, xml ) Need Help??


in reply to Sorting HOH

As ysth says your question is a bit vague. Anyway, here's an approach that you can start to work with.

use Hash::Flatten qw/ flatten unflatten /; sub pair { ... } # 1,2,3,4 => [1,2],[3,4] my %data; $data{1} = {'a' => 10, 'b' => 5, 'c' => 20 }; $data{2} = {'a' => 90, 'b' => 15, 'c' => 40 }; my @sorted = sort { $a->[1] <=> $b->[1] } pair(%{flatten(\%data)}); print $_->[0], "\n" for @sorted[0..2]; __END__ 1.b 1.a 2.b
You'll have to implement &pair yourself.

ihb

See perltoc if you don't know which perldoc to read!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-10-23 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (238 votes). Check out past polls.

    Notices?