The documentation you're looking for is available at this URL.
http://search.cpan.org/~nwclark/perl-5.8.8/lib/sort.pm
Read the Description section -- particularly the parts about "stablility".
There are two solutions.
A: use sort 'stable';
B: sort on both status and name as follows.
sort { $a->{'status'} <=> $b->{'status'} || $a->{'name'} cmp $b->{'name'} }
Both solutions should produce:
{name => 'a', status => 0}, {name => 'd', status => 0}, {name => 'b', status => 1}, {name => 'c', status => 1}
Regards,
... Dewey
[EMAIL PROTECTED] wrote on 05/05/2006 11:12:22 AM:
> Hello all,
>
> I can't find anything in the doc about whether Perl's sort function
> maintaining the order in equivalent subsequences. Suppose I have an
> array of hashrefs that looks like this:
>
> {name => 'a', status => 0}, {name => 'b', status => 1}, {name =>
> 'c', status => 1}, {name => 'd', status => 0}
>
> and I sort { $a->{'status'} <=> $b->{'status'} }
>
> Should I expect the result (order of the names) to always be ('a',
> 'd', 'b', 'c'), or could it be, for example, ('d', 'a', 'b', 'c')
> (i.e., could two entries with the same status value change relative order)?
>
> Joe
>
> Joseph Discenza, Senior Programmer/Analyst
> mailto:[EMAIL PROTECTED]
>
> Carleton Inc. http://www.carletoninc.com
> 574.243.6040 ext. 300
> Fax: 574.243.6060_______________________________________________
> Perl-Win32-Users mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
