Might seem really obvious, but you can't define a sort for hash keys without using the keys in the sort parameters. sort keys %hash works, but if you define the sort, such as sort {$b <=> $a} keys %hash, it doesn't. Try this instead. (I was asked by a friend about this. Solution might help other people learning.)
@sortedkeys = (sort { $hash{$b} <=> $hash{$a} } keys (%hash));

Replies are listed 'Best First'.
Re: Sorted hash keys
by I0 (Priest) on Dec 21, 2000 at 20:15 UTC