It has something to do with BEGIN
I have found this information:
BEGIN: A BEGIN code block is executed as soon as possible, that is, the moment it is completely defined, even before the rest of the containing file (or string) is parsed
So I suspect that that means that in case the BEGIN is not there the parser will detect the variable $x before it is created. In case the BEGIN is there, it is guarantied to execute that block first, so before it sees $x (or in this case actually $main::x) and by that time it exists because the block has already been executed.
edit: It even looks like that BEGIN turns off certain warnings for this reason:
perl -MO=Deparse -wMstrict -e "{ package bla { *::x=\$a } }" Name "main::x" used only once: possible typo at -e line 1. ...
perl -MO=Deparse -wMstrict -e "BEGIN { package bla { *::x=\$a } }" # No problem
In reply to Re^2: Logic for importing and strict vars?
by Veltro
in thread Logic for importing and strict vars?
by haukex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |