in reply to Initialize variable in BEGIN
Hence you are declaring 3 different² variables in your code.
Since declarations happen at compile time it's safe to have only one in the surrounding scope (block or file) This will cover all nested scopes.
Like demonstrated by hippo in the other reply on the file scope.
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
¹) See https://perldoc.perl.org/5.6.0/perldelta#%22our%22-declarations
²) That's probably confusing, three different lexical aliases are declared, but all store inside the same package variable. It's just that the values are switched whenever the scope is changing, giving the appearance of different variables. Similar to local
|
|---|