Compiling Your Code
Perl is always in one of two modes of operation: either it is compiling your program, or it is executing it--never both at the same time. Throughout this book, we refer to certain events as happening at compile time, or we say that "the Perl compiler does this and that". At other points, we mention that something else occurs at run time, or that "the Perl interpreter does this and that". Although you can get by with thinking of both the compiler and interpreter as simply "Perl", understanding which of these two roles Perl is playing at any given point is essential to understanding why many things happen as they do. The perl executable implements both roles: first the compiler, then the interpreter. (Other roles are possible, too; perl is also an optimizer and a code generator. Occasionally, it's even a trickster--but all in good fun.)
It's also important to understand the distinction
between compile phase and compile time, and between run phase and run
time. A typical Perl program gets one compile phase, and then one run
phase. A "phase" is a large-scale concept. But compile time and run
time are small-scale concepts. A given compile phase does mostly
compile-time stuff, but it also does some run-time stuff via
BEGIN
blocks. A given run phase does mostly
run-time stuff, but it can do compile-time stuff through operators
like eval
STRING
.
In the typical course of events, the Perl compiler reads through your entire program source before execution starts. This ...
Get Programming Perl, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.