[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] sorting; difference in Mac/Unix



Xah wrote:

>What the following script does is to generate an array of array, called @yearMonthArray. Essentially, @yearMonthArray = ([1997,11],[1997,12],[1998,1],[1998,2],[1998,3],...).
>
>Now the script sort it using
>
> my(@newA) = sort {$b <=> $a} @yearMonthArray;
>

Since @yearMonthArray contains references to array, when you compare
the elements in the array, you are compariing the stringified version
of the reference numerically. All you are comparing is the memory
addresses of each element, and its no surprise to me that Linux and
MacPerl allocate memory differently.

I think what you want is something like:

my(@newA) = sort {$b->[0] <=> $a->[0] or $b->[1] <=> $a->[1] } 
                   @yearMonthArray;-- 
Andrew Langmead

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch