The Life Cycle of a Perl Program
You can break up the life cycle of a Perl program into four distinct phases, each with separate stages of its own. The first and the last are the most interesting and the middle two are optional. The stages are depicted in Figure 16-1.

Figure 16-1. The life cycle of a Perl program
- 1. The Compilation Phase
During phase 1, the compile phase, the Perl compiler converts your program into a data structure called a parse tree. Along with the standard parsing techniques, Perl employs a much more powerful one: it uses
BEGINblocks to guide further compilation.BEGINblocks are handed off to the interpreter to be run as soon as they are parsed, which effectively runs them in FIFO order (first in, first out). This includes anyuseandnodeclarations; these are really justBEGINblocks in disguise.UNITCHECKblocks are executed as soon as their compilation unit is finished being compiled; these are used for per-unit initialization. AnyCHECK,INIT, andENDblocks are scheduled by the compiler for delayed execution.Lexical declarations are noted, but assignments to them are not executed. All
evalBLOCKs,s///econstructs, and noninterpolated regular expressions are compiled here, and constant expressions are preevaluated. The compiler is now done, unless it gets called back into service later. At the end of this phase, the interpreter is again called up to execute ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access