Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Sorting HOH

by ihb (Deacon)
on May 02, 2005 at 15:18 UTC ( [id://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!