in reply to Re^2: sort by a multiple columns
in thread sort by a multiple columns

I'm sorry, but neither you nor Roy Johnson follow the OP insofar as he would like undefined array elements to be treated like infinity rather than zero, that is, he says he wants
3,4,23,4,5 3,4,56,2,4 3,4
instead of
3,4 3,4,23,4,5 3,4,56,2,4
Might just have been a typo though, as it's quite unusual.
CombatSquirrel.

Entropy is the tendency of everything going to hell.

Replies are listed 'Best First'.
Re^4: sort by a multiple columns
by Roy Johnson (Monsignor) on Sep 08, 2004 at 23:20 UTC
    Good observation. The fix is surprisingly simple:
    sort { ## Compare through the shorter only for (0..(@$a>@$b ? $#{$b} : $#{$a})) { return $a->[$_] <=> $b->[$_] || next } ## If no difference, the longer array is first @$b <=> @$a;

    Caution: Contents may have been coded under pressure.
Re^4: sort by a multiple columns
by BrowserUk (Patriarch) on Sep 08, 2004 at 22:20 UTC

    Don't be sorry, your absolutely right :) Especially as my attempted correction of Roy Johnson's code was crap anyway.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon