in reply to how do i sort hash values?
This is a FAQ. See perlfaq4.my %hash = (f => 'd', c => 'a', b => 'e'); my @keys_ordered_by_value = sort { $hash{$a} cmp $hash{$b} } keys %has +h; # ^^^ # \|/ # to sort numeric values use <=> here -------+ # to sort in reverse order swap $a and $b: { $hash{$a} cmp $hash{$b} + } foreach my $key (@keys_ordered_by_value) { print "key = $key, value = $hash{$key}\n"; }
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|