in reply to "my" variable masks earlier declaration in same scope
You may have code like this:
my $txt = 'hello world'; print "$txt\n"; # prints "hello world" my $txt = 'oh noes'; print "$txt\n"; # prints "oh noes"
Instead, you may want this:
my $txt = 'hello world'; print "$txt\n"; $txt = 'oh noes'; # note, no "my" print "$txt\n";
It does the same thing, but it doesn't produce a warning. If you use diagnostics, it will tell you this about it:
(W misc) A "my" or "our" variable has been redeclared in the current scope or statement, 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.
|
|---|