Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: sort by a multiple columns

by CombatSquirrel (Hermit)
on Sep 08, 2004 at 21:58 UTC ( [id://389484]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://389484]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-28 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found