Chapter 3. The Perl Interpreter
The perl executable, normally installed in /usr/bin or /usr/local/bin on your machine, is also called the perl interpreter. Every Perl program must be passed through the Perl interpreter in order to execute. The first line in many Perl programs is something like:
#!/usr/bin/perl
For Unix systems, this #!
(hash-bang or shebang) line
tells the shell to look for the
/usr/bin/perl program and pass the rest of the file
to that program for execution. Sometimes you’ll see different
pathnames to the Perl executable, such as /usr/local/bin/perl.
You might see perl5 instead of perl on sites that still depend
on older versions of Perl.
Or you’ll see command-line options tacked on the end, such as
the notorious -w switch, which produces warning messages.
But almost all Perl programs
on Unix start with some variation of this line.
If you get a mysterious
“Command not found” error on a Perl program, it’s
often because the path to the Perl executable is wrong.
When you download Perl programs off the Internet, copy them
from one machine to another, or copy
them out of a book (like this one!), the first thing you
should do is make sure that the #!
line points to the
location of the Perl interpreter on your system.
So what does the Perl interpreter do? It compiles the program internally into a parse tree and then executes it immediately. Perl is commonly known as an interpreted language, but this is not strictly true. Since the interpreter actually does convert ...
Get Perl in a Nutshell 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.