It appears that the test for barewords happens after compiling is finished. The test for undeclared variables also appears to wait until compilation is finished but happens sooner:
> perl -w use strict; BEGIN { while( calldepth < 5 ) { sleep 1; } print $n; } Global symbol "$n" requires explicit package name at - line 6. BEGIN not safe after errors--compilation aborted at - line 7.
Note that I don't even have to type end-of-file there but that the error didn't appear until I finished the BEGIN block. If the infinite loop ever finished, then you'd get the 'bareword' error:
> perl -w use strict; BEGIN { my $n= 5; while( calldepth < $n ) { warn $n--; } } Argument "calldepth" isn't numeric in numeric lt (<) at - line 4. 5 at - line 5. 4 at - line 5. 3 at - line 5. 2 at - line 5. 1 at - line 5. my $x = 5; BEGIN { warn "interesting" } Bareword "calldepth" not allowed while "strict subs" in use at - line +4. BEGIN not safe after errors--compilation aborted at - line 12.
Note that I still didn't have to type end-of-file. And it didn't take until the file was finished being compiled. So it seems like this might be a problem that can be fixed. The BEGIN block can't be run until it is done being compiled. The check for barewords is happening after the block is done being compiled but after the block is run.
So the next step is to figure out why it waits (until a subsequent BEGIN block is declared, in the above example) before the check for barewords is done?
Updated.
- tye
In reply to Re: Why no bareword warnings while inside of BEGIN (more)
by tye
in thread Why no bareword warnings while inside of BEGIN
by JayBonci
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |