Gunwant Singh wrote:
> Rob Dixon wrote:
>>
>> my @sorted = sort {
>> my @a = split /:/, $a;
>> my @b = split /:/, $b;
>> $a[1] <=> $b[1];
>> } @list;
>>
>> print "$_\n" foreach @sorted;
>
> I got what your code says.Thanks a lot!!
> Can you tell me what is $a[1] <=> $b[1] doing for me?
It compares the second elements of arrays @a and @b numerically. <=> is the
numeric equivalent of the 'cmp' operator which compares strings in dictionary
order, which is the default sort mode. That is to say,
sort @list;
is identical to
sort {$a cmp $b} @list;
This is from perldoc perlop
> Binary "<=>" returns -1, 0, or 1 depending on whether the left argument
> is numerically less than, equal to, or greater than the right argument.
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/