Chapter 68. Basic Perl Anatomy
Chip Salzenberg
In Components of the Perl Distribution, I described the overall content and layout of the perl distribution. Now that the stage has been set, I’ll show how perl implements the Perl language, with occasional excursions into the standard library.
We’ll survey the major portions of perl and their functions. You’ll notice that the word “perl” isn’t always capitalized in this column. That’s because Larry Wall draws a distinction between “Perl” the language and perl the program—in theory, there could be other programs besides perl that implement Perl. Thus, this article is not about “the guts of Perl” but rather “the guts of perl.”
How Perl Works
Here’s a bird’s-eye view of how perl executes your Perl programs:
- Lexical analysis
perlreads your program and breaks it down into basic syntactic elements, called tokens.- Parsing
perlfigures out the meaning of those tokens in that specific sequence.- Compilation
perlbuilds an internal structure representing operations that, when executed, will perform the actions specified by your program.- Execution
perlsteps through those operations and performs them, one by one.
Note that perl distinguishes Step 3from Step 4. The line is blurred by BEGIN {} blocks, which specify Perl code to be executed during the compilation phase-— before your program runs.
Step 3 settles one of the frequently asked questions about Perl: perl is a compiler, not an interpreter. Specifically, it’s a “load-and-go compiler.” Incidentally, current ...
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