Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
It is genuinely my understanding that declaring the variable within one (in-lined) sub, but using it in another, is Not A Good Thing.

Each of the anonymous subs has its own my @messages = (); statement. They are not related!(*) They do not name the same memory space (though they may well re-use some or all of the same memory at different times).

By moving the declarations outside of the subroutines, you would make them occupy the same memory and never be cleaned or re-initialised and thus they would grow unchecked and totally exacerbate the very problem your "advice" was intended to help with. (Presumably; you do not seem deliberately malicious; just <you pick the adjective>.)

(*)Each time any of the subs gets called, they get a new instance of that array, which is then discarded -- its memory space given back to the process memory pool for reuse -- when the call to the subroutine ends. The fact that they are used for similar purposes in each the 3 subroutines, and therefore are given similar names, does not mean that they have anything whatsoever in common.

(In fact, the initialisation is completely redundant, a clean, empty array is created each time the subroutines are called.)

This is how lexical (my) variables work. The fact that you don't know this beggars belief. The fact that you don't know this but still feel qualified to offer others advice, beggars disbelief!


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.

In reply to Re^4: How to deal with the fact that Perl is not releasing memory by BrowserUk
in thread How to deal with the fact that Perl is not releasing memory by carlbolduc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (7)
    As of 2014-07-13 19:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

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








      Results (251 votes), past polls