Paul Hodges wrote:
: Try flipping the hash.
:
: my %flipped;
: @flipped{values %HASH} = keys %HASH;
:
: That makes the keys of %HASH the values of %flipped, with the matching
: values of %HASH being the keys to which they are assigned.
: Now just do it the easy way.
:
: for my $key (sort keys %flipped) {
: print $flipped{$key};
: }
If the values are numeric, you'll want to do the sort like this:
sort {$a <=> $b} keys %flipped
Otherwise, they will sort like text, and you'll get an order like
1,10,11,12,13,14,15,16,17,18,19,2,20,21,...
<=> does numeric comparisons
cmp does text comparisons; it's the default for sort().
-- tdk