"be consistent" | |
PerlMonks |
Explanation of warning created when over using "my"by Tatnall (Beadle) |
on Sep 21, 2006 at 14:53 UTC ( [id://574140]=perlquestion: print w/replies, xml ) | Need Help?? |
Tatnall has asked for the wisdom of the Perl Monks concerning the following question: Often, I add "my" to variables that have previously been declared generating this warning: "my" variable $pet masks earlier declaration in same scope. I use "my" again to 'clobber' the old value, I could use undef($pet); too I guess. In perldiag I found this: (W) A lexical variable has been redeclared in the same scope, effectively eliminating all access to the previous instance. This is almost always a typographical error. Note that the earlier variable will still exist until the end of the scope or until all closure referents to it are destroyed. I understand what the warning means, but I don't understand why it generates a warning I'm missing something important. Is it bad coding style? Does it take up more memory? What are the drawbacks to redeclaring vesus undefining and then using the variable again? Example:
Thanks, Tatnall
"Recognizing who we aren't is only the first step toward knowing who we are." - Os Guinness
Back to
Seekers of Perl Wisdom
|
|