Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: sort by a multiple columns

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 BrowserUk (Patriarch) on Sep 08, 2004 at 18: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
Re^4: sort by a multiple columns
by Roy Johnson (Monsignor) on Sep 08, 2004 at 19: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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://389484]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.