On Thu, 19 Jul 2001, Miles Sapp wrote:
> Can someone please explain what a BEGIN block does? I see from my books
> and online documentation that BEGIN blocks are run at compile time and
> are run only once, but I'm not sure how that's different from any other
> perl code that's not in a loop. Also, in my test script (below) the
> block would only work if it was before the uninitialized variable, which
> seems odd. Thanks,
The difference is that it is compiled *and* run at compile time (as
opposed to the rest of the code, which gets compiled, checked for syntax
errors, etc, then enters the run-time phase). BEGIN blocks are run before
even syntax checking is done for the rest of the script. This is the kind
of thing useful for creating customized include paths (which is what
happens when you 'use lib') or doing other kinds of initialization, like
setting a debug flag. The END block does the opposite -- it is always run
after the program exits, even if it dies from a caught exception (although
not from an uncaught signal).
-- Brett
http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
Oh wearisome condition of humanity!
Born under one law, to another bound.
-- Fulke Greville, Lord Brooke
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]