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

Invoking Perl

Just as with Grep, Sed and Awk, simple use of the perl command involves a program containing the commands Perl uses. This program can either be a file which is an argument to perl, or can be contained in a string named by option -e. Note that this is slightly different to the convention used by Awk. Thus, to print out Hello World! we can either invoke

perl -e 'print "Hello World!\n"'

or alternatively create a file (perlprogram, say) containing the print statement print "Hello World!" and then invoke perl on the file thus:

perl perlprogram

As we shall see, although Perl embraces all the concepts we have already encountered (such as standard input and output, pipes, processes, and so on), the syntax it uses for them is quite different.


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck