Chapter 16. Perl

Perl was created by Larry Wall in 1987 as a text processing language combining the power of the UNIX tools awk, sed, shell scripts, and some C. The name stands for "Practical Extraction and Report Language" and is also known as the "Pathologically Eclectic Rubbish Lister". It established itself quickly as the scripting language of choice for UNIX systems. The typical applications are system administration tools and batch jobs such as loading data from a file into a database. Due to its diverse background, Perl had a lot of limitations and quirks in the beginning, but became a general purpose programming language with its version 5 in 1994.

Originally I was not planning to include Perl in this book at all. Grown out of the two UNIX tools sed and awk, which were never supposed to be used for large programs, Perl is a collection of many individual features which are hard to describe on a few pages. But how can you ignore a language which is used by tens if not hundreds of thousands of programmers to solve their every day problems? I include this chapter mainly for two reasons. To give the background for the less obvious features of the scripting language Ruby covered in the next chapter, and to enable programmers to migrate the many legacy applications written in Perl during the last few years.

16.1. Software and Installation

For the examples, I'm using Perl version 5.6.1. Perl does not have a built-in interactive environment which we can use to explore the language on the command line. Instead, Perl compiles a script into some intermediate format and runs it as a whole. You can, however, run most examples with Perl's debug mode using the command perl -d -e 1.

References

The book on Perl is [WALL96]> by Larry Wall and two of his co-workers (the first edition edited by Tim O'Reilly himself). It presents the language in a rather casual way and gives a lot of background information (why Perl looks the way it does). The nutshell book [SIEVER99]> is a good desktop reference covering the most important modules including the interface to the GUI library Tk.

Larry Wall, Tom Christiansen, and Randal L. Schwartz, 1-56592-149-6, O'Reilly, 1996, Programming Perl, Second Edition.

Ellen Siever, Stephen Spainhour, and Nathan Patwardhan, 1-56592-286-7, O'Reilly, 1999, Perl in a Nutshell.

Tom Christiansen and Nathan Torkington, 1-56592-243-3, O'Reilly, 1998, Perl Cookbook.

Sriram Srinivasan, 1-56592-220-4, O'Reilly, 1997, Advanced Perl Programming.

Randal Schwartz, Tom Christiansen, and Larry Wall, 1-56592-284-0, O'Reilly, 1997, Learning Perl.