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

Perl and the Kernel

We have already mentioned some of the functions available in Perl, and have noted that functions often appear similar in name and in what they do to shell utilities. This is no accident.

Recall that a UNIX system contains at its core the kernel. The interface to this kernel is specified both in the C language (POSIX.1) and as shell commands (POSIX.2). The shell command names mimic - as far as is sensible - the names of the corresponding C procedures. For example, to create a new directory, the shell command mkdir is used, and the corresponding C procedure is called mkdir. The Perl function is also called mkdir.

The C language has been used to code the kernel, and much of the shell and Perl is written in C (or its more recent object-oriented derivative C++). The use of the names used by C to interface with the kernel thus gives the shell or Perl programmer a consistent window into the kernel. Anything (almost!) that can be coded in C on a UNIX system can be written in the shell or in Perl.


Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck