Perl Tips

Perl is the Swiss Army Knife of scripting languages. It can do everything shell scripts and standard Unix tools like grep, sed, and awk can do, plus much, much more.


A unique feature of Perl is that it doensn't come with just one man page, but with a whole slew of man pages that describe various aspects of Perl, and serve as tutorials, reference manuals, and FAQ pages. Here are some of the most useful of these pages for beginners:

Line-based operation

The simplest way to use perl in commandline mode is as a filter that operates on a file (or on standard input), manipulates the file one line at a time, and outputs the result to standard output, much like standard Unix utilities like grep, sed, and awk work.

The basic structure of the command is one of the following:

The commandline options used here have the following meaning: The following examples illustrate the use of Perl for line-by-line processing of files.

Operating on entire files

Perl's power really shines when one wants to perform operations on chunks of files that extend over multiple lines (e.g., deleting line breaks in paragraphs). Standard Unix utilities like sed or awk are ill-suited for that, but with Perl this is easy by changing the record separator (which defaults to a linebreak) to something else using the '-0' option. Of particular interest are the following cases: Here are some examples using these modes:

Cool stuff

Sources of practice material

Last modified: Mon 20 Jul 2009 10:07:23 AM CDT A.J. Hildebrand