Do you know where your variables are? | |
PerlMonks |
Re: help sorting hash of hashes by valueby kcott (Archbishop) |
on Apr 07, 2022 at 08:12 UTC ( [id://11142786]=note: print w/replies, xml ) | Need Help?? |
G'day Special_K, Your basic problem is not taking into account the fact that hashes are unordered. You'll get foo1, foo2 & foo3 returned in a random order when you call keys %hoh_test; and, for each of those, you'll get bar & baz returned in a random order when you call keys %{$hoh_test{$foo}}. Here's my take on a solution:
This produces the same output on each run:
Just to exemplify the unordered nature of hashes, here's what @hoh_data looked like, on two separate runs, before passing to sort { $b->[2] <=> $a->[2] }:
Update: Well, I made a real mess of keys %{hoh_test($foo}}. Now fixed: keys %{$hoh_test{$foo}}. — Ken
In Section
Seekers of Perl Wisdom
|
|