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

Input and output

A feature of the shell is that input and output, as simple data streams, are fundamental to its working. In other languages, such as Java or C, input and output can be much more complex, and the programmer needs to be aware of the type of data they are reading in or sending to an output device or file.

For example, if a program were to write data to many different files, then a shell program that relied on redirection of the standard output stream would become unwieldy and difficult to write.

Perl retains the simplicity of the shell whilst allowing the programmer a greater variety of methods for reading and writing data. It is equipped with five predefined variables for input and output (known as filehandles):

STDIN is the standard input stream
STDOUT is the standard output stream
STDERR is the standard output stream
ARGV is an array containing the arguments to the program
DATA is the Perl equivalent of a here-document

Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck