This discussion provides a summary of basic Perl features, organized in categories consistent with the structure of the language. It is intended to complement, rather than replace, other Perl resources, such as published texts, reference books, on-line tutorials, and discussion groups. In particular, you may wish to use it in conjunction with the course Perl-CGI Tutorial.
If you are just learning Perl, you may also wish to consult a text, such as the Schwartz (with Wall) Learning Perl, published by O'Reilly & Associates, or their more advanced Programmig Perl, by Wall and Schwartz.
Perl Basics has two main goals. First, it provides a succinct summary of major Perl elements. Second, it provides perspective and relates features to one another. Thus, you may think of it as an extended and structured checklist, with commentary.
The discussion is oriented toward answering two questions:
- What are the things Perl provides you to work with?
- What can you do to those things?
The discussion includes six major sections:
- Variables and their Related Operators
- Control structures
- Regular Expressions
- System Operators
1. Variables and their Related OperatorsPerl provides three kinds of variables: scalars, arrays, and associative arrays. The discussion includes the designation of these three types and the basic operators provided by Perl for their manipulation.
2. Control StructuresPerl is an iterative language in which control flows from the first statement in the program to the last statement unless something interrupts. Some of the things that can interrupt this linear flow are conditional branches and loop structures. Perl offers approximately a dozen such constructs. Each of these basic constructs are described along with examples illustrating their use.
3. FunctionsFunctions are a fundamental part of most programming languages. They often behave like an operator, producing a change in the value of some variable or returning a value that can be assigned to a variable. They also control the flow of execution, transferring control from the point of invocation to the function definition block and back. Thus, they combine properties of the two preceding discussions. The discussion will cover both the designation of functions and their invocation and use.
4. Regular Expressions and Related OperatorsRegular expressions are strings that can be recognized by a regular grammar, a restricted type of context-free grammar. Basically, they are strings that can be parsed left to right, without backtracking, and requiring only exact symbol matching, matching of a symbol by a category of symbols, or matching of a symbol by a specified number of sequential occurrences of a symbol or category.
Perl provides a general mechanism for specifying regular expressions. It also provides several operators that manipulate strings based upon the evaluation of a regular expression.
The discussion will begin by describing the various mechanism for specifying patterns and then discuss expression-based operators.
5. Input/OutputPerl provides basic I/O for both the standard input (keyboard) and output (display) devices and for files in the UNIX file system. More sophisticated I/O is provided through the UNIX DBM library. These various I/O capabilities are discussed.
6. System OperatorsPerl offers a number of operators that mimic or call UNIX system operators or analogous operators for other operating systems. The discussion here will be cast in the context of UNIX and will assume familiarity with basic UNIX facilities.
Perl system operators can be roughly divided into two large categories: file/directory operators and process operators. Both types are discussed.