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

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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    [james28909]: politicians making jobs for themselves? that is absurd! we all know how hard those politicians have it, having to take millions from lobbiest while screwing over their citizens. have a little sympathy why dont ya!

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (9)
    As of 2017-12-15 18:33 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (442 votes). Check out past polls.