in reply to Re: DANGER - was Re: Re: Syntax Error Checking
in thread Syntax Error Checking

A BEGIN block is equivalent to a subroutine definition of a subroutine called BEGIN, followed immediately by an invocation and removal of that subroutine at compile time. So for example, in the case of:
sub fred { blah blah; sub barney { print "hey there"; } foo foo; }
we'd get the barney subroutine defined, with no connection (except closures if any) with the fred subroutine. Invoking fred would do nothing to or about barney. Replace barney with BEGIN, and you get the same behavior with respect to fred, except that BEGIN is now executed immediately even before compiling foo foo. Drop the "sub" keyword, and the same behavior applies.

-- Randal L. Schwartz, Perl hacker