in reply to Advanced Sorting

It's hard to see what you are asking. If you are trying to sort by name and then age, your solution does not quite work. Here's some code to do that:
@sorted = sort { unless ($a->{'name'} cmp $b->{'name'}) { $a->{age} <=> $b->{age} } } @data;
I used the following list:
jim 18 bob 24 bob 14 cathy 98 cathy 45
Which gets sorted to:
bob 14 bob 24 cathy 45 cathy 98 jim 18

Replies are listed 'Best First'.
RE: Re: Advanced Sorting
by dsdisc (Initiate) on Apr 20, 2000 at 02:07 UTC
    Thanks for the reply, but that's not quite what I need. I need to sort on values that may be all strings OR all numbers, not a primary then secondary search. And one small optimization to your code would be:
    @sorted = sort { <BR> $a->{'name'} cmp $b->{'name'} || $a->{age} <=> $b->{age} <BR> } @data; <BR>
    Perl's sorting algorithm will return '0' if the "cmp" is equal, defaulting to the secondary sort.