in reply to Why no bareword warnings while inside of BEGIN

I don't know the answer, but I suspect it has to do with the "run-as-soon-as-possible" nature of BEGIN blocks. One reason I suspect this is that if you change calldepth < 5 to calldepth > 5, you get a bareword error. Also, you get a bareword error (or at least, I do) if you run a similar one-liner:

perl -e 'use strict;BEGIN{if (bareword > 1) {1} }'
which probably makes the answer obvious to some people, though it doesn't to me. :-)



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

Replies are listed 'Best First'.
Re: Re: Why no bareword warnings while inside of BEGIN
by JayBonci (Curate) on Mar 22, 2004 at 22:59 UTC
    Okay, so a pared down example of why this is kinda scarry is this:
    perl -e "use strict; BEGIN { while(bareword < 1) {1} }"
    Cycles forever. No error
    perl -e "use strict; BEGIN { while(bareword > 1) {1} }"
    Throws the bareword error ...wierd. --jay


        --jaybonci
      JayBonci,
      See my post below. The while loop is infinite because 0 < 1. It never enters the loop when 0 > 1. Not throwing the error until after the code is run may or may not be expected behavior as tye points out.

      Cheers - L~R