When perl gets to the end of compiling a BEGIN block, it temporarily stops compiling, executes the code in the block, then continues compiling. Similarly, when Perl sees a 'use' while compiling, it temporarily stops the current compile, reads in the file referenced by the 'use', compiles it, executes it, calls the import function(), then continues off compiling at the statement following the 'use'.
In your original code, the Perl interpreter starts compiling the code in your BEGIN block, sees the 'use', reads in and compiles the file, calls its import method, then continues compiling the rest of the code in the BEGIN block. (At this point, the import has already affected the current package's symbol table for any subsequent code). Finally the end of the BEGIN block is reached, compilation pauses and the BEGIN block is executed.
At this point your if statement is executed, which by now has been optimised away to a noop, since it has an empty body (since 'use' is invisible at runtime).
Dave.
In reply to Re^3: "Safe" ways for Carp to report errors to browser?
by dave_the_m
in thread "Safe" ways for Carp to report errors to browser?
by argv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |