Chapter 2. Getting Started with Perl
Now we’re ready to add the centerpiece of your information toolkit: Perl, the “Swiss army chainsaw” for web content creators. This chapter explains how to locate Perl on your system, and walks you through running a very simple Perl script. Along the way it explains command paths, and gives a quick lesson on Unix file permissions. Next it covers Perl variables, quoting, and then finishes by explaining how to run a Perl CGI script (which means running a script via your web server, with the output of the script being returned to your web browser).
Finding Perl on Your System
The first thing we need to do to get you running Perl scripts is to verify that Perl has already been installed on your server, find out where it is, and check to see what version it is.
Log into a shell session and enter the command which perl
. The which command
prints out the full path to the program that will run when you enter
the program’s name by itself:
[jbc@andros jbc]$ which perl
/usr/bin/perlSo, in this case, I now know that the perl
interpreter is located at /usr/bin/perl. Your copy
of perl may be located somewhere else. Wherever it
is, write down the location. You’ll need to know it later.
Note
If your web server doesn’t have the which
command, you can try finding the location of Perl using the similar
command whereis
, giving it the -b
option to limit its output to binary files, as in:
[jbc@andros jbc]$ whereis -b perl
perl: /usr/bin/perl /usr/local/bin/perlWhat ...
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