Am Freitag, 13. Februar 2004 01:40 schrieb Larry Wall: > On Thu, Feb 12, 2004 at 04:29:58PM -0500, Uri Guttman wrote: > : again, confusing. why should the order of a binary operator mean so > : much? the order of a sort key is either ascending or descending. that is > : what coders want to specify. translating that to the correct operator > : (cmp or <=>) and the correct binary order is not the same as specifying > : the key sort order and key type (int, string, float). > > Uri is dead on with this one, guys. As I listen to this mails, I get the feeling that something like this is wanted:
Key generation: @unsorted_temp = map { $k1=$_.func1('a'); # ASC $k2=$_.func2('we'); # DESC [ $_, $k1, $k2 ]; } @unsorted; Now we've got an array with keys and the objects. Sorting: @sorted = sort { $a->[1] cmp $b->[1] || $b->[2] <=> $a->[2] || } @unsorted_temp; These things would have to be said in P6. So approx.: @sorted = @unsorted.sort( keys => [ { $_.func1('a'); }, { $_.func2('we'); } ], cmp => [ cmp, <=> ], order => [ "asc", "desc"], key_generation => "lazy", ); That would explain what I want. Maybe we could turn the parts around: @sorted = @unsorted.sort( 1 => [ { $_.func1('a'); }, cmp, "asc"], 2 => [ { $_.func2('we'); }, <=>, "desc"], ); or maybe use a hash instead of an array: @sorted = @unsorted.sort( 1 => [ key => { $_.func1('a'); }, op => cmp, order => "asc"], 2 => [ key => { $_.func2('we'); }, op => <=>, order => "desc"], ); If that's too verbose? I don't think so; I've stumbled often enough on $a <=> $b vs. $b <=> $a and similar, and the above just tells what should be done. Regards, Phil