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 runtime, 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 runtime. A typical Perl program gets one
compile phase and then one run phase. A “phase” is a large-scale concept.
But compile time and runtime are small-scale concepts. A given compile
phase does mostly compile-time stuff, but it also does some runtime stuff
via BEGIN blocks. A given
run phase does mostly runtime 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 is when Perl ...
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