Think about Loose Coupling | |
PerlMonks |
•Re^5: What can we assume in a BEGIN block ?by merlyn (Sage) |
on Oct 04, 2004 at 12:52 UTC ( [id://396211]=note: print w/replies, xml ) | Need Help?? |
It's really rather obvious when you pay attention to the documented compile-time vs run-time components of things.
For example, require is executed at run-time, first compiling the referenced code, then running it immediately after (because it is essentially a super-eval, which compiles and runs code at runtime). BEGIN-blocks move the enclosed code from runtime to compiletime. Since "use" is a combination of BEGIN and require, it causes an external file to be compiled, then executed, during the compilation of the current file. Also, variables are declared at compile time, subroutines are defined at compile time, but the initialization of variables doesn't happen until runtime. Using basic rules like this, and paying attention to the other notes (like how //o and eval work, for example), it's always possible to work out the execution order "from first principles". -- Randal L. Schwartz, Perl hacker
In Section
Seekers of Perl Wisdom
|
|