Main index

Introducing UNIX and Linux


Perl

Overview
Introduction
      Why yet another utility?
      Beginning Perl
      Invoking Perl
      Documentation on perl
      Perl Scripts
Variables
Input and output
      Files and redirection
      Pipes
      The DATA filehandle
Fields
Control structures
Predefined Perl
      Functions
      Modules
Regular expressions
      Single character translation
      String editing
Perl and the Kernel
Quality code
When do I use Perl?
Summary
Exercises

When do I use Perl?

Use Perl whenever you want. Anything you can program in the shell can be done in Perl. It is up to you to decide when the extra complication of using Perl actually saves you time. If you want to view the first line of a file, use head. It's easy, and a Perl program would be overkill. However, if you cannot identify simple UNIX utilities to perform the task you need done, then think about Perl. Complicated shell programming gets messy, and Perl is more suitable for non-trivial tasks.

There is one other reason to use Perl - security. Suppose you write a command to be used and owned by root, and to be accessible by a general user. An example might be a program for sending email, which requires write access to system files (including log files). It is dangerous to write such a program as a shell script, since under certain circumstances a user can use their knowledge of the shell environment to gain a subshell with root privileges. This can be prevented if the program is written in Perl.


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck