Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: No garbage collection for my-variables

by BrowserUk (Patriarch)
on Sep 16, 2008 at 22:10 UTC ( [id://711813]=note: print w/replies, xml ) Need Help??


in reply to Re^2: No garbage collection for my-variables
in thread No garbage collection for my-variables

Done right, you can have both (see Re^3: No garbage collection for my-variables). That way, the unaware are not caught out, but when the facility is needed it is available.

It's the same mechanism that sort uses for in-place sorting in 5.10. I've thought about patching List::Util::shuffle() in the same way.


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.

Replies are listed 'Best First'.
Re^4: No garbage collection for my-variables
by ikegami (Patriarch) on Sep 17, 2008 at 03:10 UTC

    @a = sort @a is done in place before 5.10

    >perl580\bin\perl -MO=Concise -e"@a = sort @a" 2>&1 | find "sort" 7 <@> sort lK ->8 >perl588\bin\perl -MO=Concise -e"@a = sort @a" 2>&1 | find "sort" 7 <@> sort lK/INPLACE ->8 >perl5100\bin\perl -MO=Concise -e"@a = sort @a" 2>&1 | find "sort" 7 <@> sort lK/INPLACE ->8

    I don't have 5.8.1 to 5.8.7, so let's consult the perldeltas.

    perl584delta:

    In place sort optimised (eg @a = sort @a)

    But it was buggy in 5.8.4. perl585delta:

    The in-place sort optimisation introduced in 5.8.4 had a bug. For example, in code such as @a = sort ($b, @a), the result would omit the value $b. This is now fixed.

Re^4: No garbage collection for my-variables
by betterworld (Curate) on Sep 16, 2008 at 22:35 UTC
    It's the same mechanism that sort uses for in-place sorting in 5.10. I've thought about patching List::Util::shuffle() in the same way.

    I thought what you meant was that a subroutine can detect its being called in void context? But if I am not mistaken, 5.10's in-place sorting does not happen in void context:

    % perl5.10.0 -lwe '@a = (2,1); sort @a; print @a' Useless use of sort in void context at -e line 1. 21

    As I understand it, perl (5.10) will detect that in @a = sort @a, the destination array is the same as the source array, so it uses a more efficient algorithm (but it's still in list context).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-26 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found