Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Sort command equivalent in perl

by MidLifeXis (Prior)
on Dec 16, 2011 at 16:56 UTC ( #943985=note: print w/ replies, xml ) Need Help??


in reply to Re: Sort command equivalent in perl
in thread Sort command equivalent in perl

Will the sort still happen in memory? If it is not in memory, I do not see how this can do the @file = sort @file without data loss. If it is in memory, we are back to the original problem.

+1 for the unique approach.

--MidLifeXis


Comment on Re^2: Sort command equivalent in perl
Download Code
Re^3: Sort command equivalent in perl
by BrowserUk (Pope) on Dec 16, 2011 at 17:21 UTC

    You're right. it wouldn't work for files greater than memory.

    I thought it might for a while because of the in-place sort optimisation that came in somewhere in 5.8.x, that means that:

    @ar = sort @r;

    gets converted to sort \@ar; and sorts in place rather then copies the array to the stack and back.

    But looking at the code, it doesn't work for tied arrays:

    /* optimiser converts "@a = sort @a" to "sort \@a"; * in case of tied @a, pessimise: push (@a) onto stack, then assig +n * result back to @a at the end of this function */

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      Yup, there's the gotcha that gotme. :) I remembered that @array = sort @array doesn't make a copy, but failed to think through the fact that tie would be different.


      Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (16)
As of 2014-07-10 13:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (210 votes), past polls