Well the extended message that you quote seems clear enough in explaining that the earlier instance of the variable still exists and still takes up memory. You just can't access it. That would seem to me to be enough of a reason not to do this.

But you also need to think about what you're trying to do here. When you declare a variable, it should be for as small a scope as possible and each variable you declare should have only one use.

What are you really trying to achieve by redeclaring the variable? If you just want to put a new value into it then just overwrite the existing value. If you want to reset the variable to an undefined state then allocate undef to it. But if you're doing this to indicate that you're using the variable for a different purpose now, then that's a bad idea and you should be declaring a new variable with a different name.

So redeclaring a variable within a scope like this is a bad practice - partly because, yes, you are wasting a small amount of memory, but most importantly because it's unclear what you are trying to indicate by doing this and it is very likely to confuse your maintenance programmer.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg


In reply to Re: Explanation of warning created when over using "my" by davorg
in thread Explanation of warning created when over using "my" by Tatnall

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!
  • 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, details, 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, summary, 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.