PERL Sorting

Aaron Kilbey kilbey at
Wed Nov 28 17:09:09 CST 2001

I'm trying to do a sort where one array gets sorted by two other arrays, one
after another.
I have:
@fileArray = @fileArray[sort { $temp1[$a] <=> $temp1[$b] } 0..$#temp1];
This sorts @fileArray by the values in @temp1.
If I now do:
@fileArray = @fileArray[sort { $temp2[$a] <=> $temp2[$b] } 0..$#temp2];
I have sorted @fileArray by @temp2 yet I lose my first sort results
defeating the purpose.
I'm guesssing I have to compound the sorts but I'm not sure where the "or"
goes with this notation?

Basically looking for:
Location    IQ
Astoria      10
Astoria      40
Astoria      100
Portland    10
Portland    40
Portland    100
@temp1 being locations, @temp2 being ages.

Any Input? - Aaron Kilbey


More information about the Pdx-pm-list mailing list