From:                   "Scott, Joshua" <[EMAIL PROTECTED]>
> I'd like to know the best/easiest way to sort a hash based on the
> values of it's keys.  Here is a snippet of my code.
> 
> %somehash=();
> 
> foreach (@somearray) {
>         $somehash{$_}++;
> };
> 
> Basically I'm getting a count of unique items in an array and I want
> to sort by the number of each item.  I've read some documentation and
> it says to do a sort with the cmp feature, but I don't know the names
> of they keys I need to compare.

@sorted = sort {$somehash{$a} <=> $somehash{$b}} keys %somehash;

The first parameter to sort() may be a block, in this block the 
elements of the list being sorted that are to be compared are aliased 
as $a and $b.

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to