http://www.perlmonks.org?node_id=338813


in reply to Why no bareword warnings while inside of BEGIN

JayBonci,
If you want to see it blow up you will have to do:
BEGIN { while( calldepth < 5 ) { last; } }
From perldoc perlmod
A BEGIN subroutine is executed as soon as possible, that is, the moment it is completely defined, even before the rest of the containing file is parsed.

You have put it into an infinite loop - never giving it a chance to throw the error.

Cheers - L~R

Replies are listed 'Best First'.
Re^2: Why no bareword warnings while inside of BEGIN (no)
by tye (Sage) on Mar 22, 2004 at 23:25 UTC

    The BEGIN block *can't* be run until the block is finished being compiled. If the block is finished being compiled, it is reasonable to expect that barewords would have been detected. As I show elsewhere, other types of 'strict' errors are handled correctly here.

    So I don't see how your reading of the documentation explains this problem away. The quoted section says that it runs before the "rest of the containing file is parsed". The error is in the code being run. It certainly can and should report fatal errors in that code before it runs it.

    - tye        

      tye,
      So this is a bug/feature, I see it in your reply below.
      I thought:

      Because a BEGIN block executes immediately,...

      Meant that it executed and then execeptions were thrown. After running it through perl -MO=Deparse, I thought it was expected behavior since it doesn't seem to matter what kind of loop it is - the error isn't thrown until after it is completed.

      Cheers - L~R

      Update: Changed bug/feature to statement rather than question after seeing tye's reply further down in thread