Perl-Sensitive Sunglasses | |
PerlMonks |
Re: variable has value but then become emptyby sundialsvc4 (Abbot) |
on Sep 09, 2015 at 14:44 UTC ( [id://1141423]=note: print w/replies, xml ) | Need Help?? |
Also consider the implications of the following bit of code, which compiles and runs without errors or warnings: Whose output is: foo bar The definition of $foo which exists within the anonymous block conceals, without warning, the variable of the same name that exists outside the block. Two entirely distinct values are maintained, each referred-to at different times and in different scopes by the same variable name. Within the block, the value "bar " cannot be reached, and there is nothing to alert you to the probably-unintentional conflict. This is not “incorrect” behavior. It is, in fact, by design, although it might be slightly different from other languages you have used (and whose error, warning, and informational messages you might have come to rely upon). This it just might be yet-another reason why “global variables are not a particularly good idea.”
In Section
Seekers of Perl Wisdom
|
|