Tuesday, November 20, 2001, 6:27:44 PM, Brett W. McCoy wrote:

BWM> On Tue, 20 Nov 2001, Franck FASANO wrote:

>> Here is a little code :
>>
>> --------------
>> my @trav= ( 1, 12, 5, 3);
>> @trav=sort { $b cmp $a } @trav;
>>
>> foreach (@trav) {
>>  print " $_ ";
>> }
>> --------------
>>
>> After exec, we have :
>>  5  3  12  1

BWM> You're using the wrong operator.  You want { $b <=> $a} for your
BWM> comparison.

because <=> will do a numeric comparison, whereas cmp will do a string
comparison...

as strings "12" is less that "5", but as numbers 5 is obviously less
than 12.


-- 
Best regards,
 Daniel


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to