We don't bite newbies here... much | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
From perlsyn: NOTE: The behaviour of a my, state, or our modified with a statement modifier conditional or loop construct (for example, my $x if ...) is undefined. The value of the my variable may be undef, any previously assigned value, or possibly anything else. Don't rely on it. Future versions of perl might do something different from the version of perl you try it out on. Here be dragons. Update: Heh, Eily and I posted within 4 seconds of another ;-) Update 2: Historically, sometimes this "feature/bug" was (ab)used to make variables "static", just two references of many found with a quick search: Unusual Closure Behaviour, Re: Making a variable in a sub retain its value between calls. The better ways to do this are described in Persistent Private Variables:
But nowadays, anywhere you see the pattern, it should be considered a bug, see "Using my() in false conditional" in perldeprecation. On Perl 5.26:
Update 3: Apparently, the warning "Deprecated use of my() in false conditional" first showed up in Perl 5.10 and became a default warning in 5.12. Note that your Perl 5.10.1 is now more than eight years old, and you should upgrade. Also, you should generally use warnings; (Use strict and warnings). In reply to Re: Variable Scope (updated)
by haukex
|
|