>>>>> "LP" == Luke Palmer <[EMAIL PROTECTED]> writes:
>> # P5: @sorted = sort { $a->foo('bar')->compute <=> $b->foo('bar')->compute } >> # @unsorted >> # or: @sorted = map { $_->[1] } >> # sort { $a->[0] <=? $b->[0] } >> # map { [ $_->foo('bar')->compute, $_ ] } >> # @unsorted >> @sorted = sort &infix:<=>, key => { $_.foo('bar').compute } <== @unsorted; LP> Ok, I have to say, that's pretty good. Er, really good. I like it a LP> lot. how do you select descending order? and how do you selecte that per key? you can't provide a binary operator without also providing the order. and what about different key types? the <=> and cmp operators are not enough information needed to do complex sorts. collating sequences are another issue. you need to have that info on a perl key basis. >> I think my suggestion wins big here. We've only had to specify how >> to extract the key, and sort itself takes care of everything else. >> And it looks to me like this sort function has enough information >> about the programmer's intent for it to optimise in all sorts of >> exciting ways -- it should be able to do the equivalent of the GRT >> internally, for example. sort can't figure it out without you telling it things. you need more than just key extraction. >> Just for kicks, this one demonstrates all the features. It's the same as >> before, but in descending order: >> >> @unsorted >> ==> sort &infix:<=>, desc => 1, key => { $_.foo('bar').compute } >> ==> @sorted; >> >> What problems can anyone spot with this suggestion? multiple keys with each having different comparisons and different sort orders. LP> @unsorted LP> ==> sort { $^b <=> $^a }, key => { .foo('bar').compute } LP> ==> @sorted LP> Which people have made pretty clear that they don't like. as i have said before. needing to have $a and $b in the correct order is bug prone and confusing to many. uri -- Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org