in reply to Sorting hashes on non-keys

The sort language construct accepts a code block argument for use as a custom comparison operator.

Example:

@list = sort {$b cmp $a} @list

The above code segment sorts @list in reverse to what is normally expected ('z', 'y', 'x', ..., 'a'). This can be extended in many ways -- one of which is to sort $msgid based on a value derived from $msgid:

@msgids = sort { $mailarray{$a}{'from'} cmp $mailarray{$b}{'from'} } keys %mailarray;

You should read up on 'sort' using 'perldoc -f sort'. Good luck.

Replies are listed 'Best First'.
Re: Re: Sorting hashes on non-keys
by Anonymous Monk on Feb 22, 2003 at 17:51 UTC
    Thanks for the example. I did read up on sort, but didn't realize that I could do it the way you mentioned.