winnie_pooh has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; my %HoH = ( 0 => { b => 2, a => 1, e => 5, c => 3, d => 4, } ); foreach my $key (sort { $HoH{0}{$a} cmp $HoH{0}{$b} } keys $HoH{0}) { my $value = $HoH{0}{$key}; print $value->{$key}, "\n"; }
In the above hash of hashes (showed just entry for $HoH{0}), I'd like to sort the inside hash by values, so that I get output like this:
1 -> a 2 -> b 3 -> c 4 -> d 5 -> e
I know the loop is wrong... any help? Thanks a lot!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sorting hash of hashes by values
by tangent (Parson) on Nov 15, 2013 at 23:12 UTC | |
Re: Sorting hash of hashes by values
by choroba (Cardinal) on Nov 15, 2013 at 23:14 UTC | |
Re: Sorting hash of hashes by values
by AnomalousMonk (Archbishop) on Nov 16, 2013 at 20:53 UTC | |
Re: Sorting hash of hashes by values
by AnomalousMonk (Archbishop) on Nov 16, 2013 at 21:10 UTC | |
Re: Sorting hash of hashes by values
by LanX (Saint) on Nov 15, 2013 at 23:11 UTC |
Back to
Seekers of Perl Wisdom