Introduction to Perl

Kirrily Robert

Open Publications License 1.0

Copyright (c) 1999-2000 by Netizen Pty Ltd. Copyright (c) 2000 by Kirrily Robert . This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, vX.Y or later (the latest version is presently available at http://www.opencontent.org/openpub/).


Table of Contents
1. Introduction
Course outline
Assumed knowledge
Module objectives
Platform and version details
The course notes
Other materials
2. What is Perl
In this chapter...
Perl's name
Typical uses of Perl
Text processing
System administration tasks
CGI and web programming
Database interaction
Other Internet programming
Less typical uses of Perl
What is Perl like?
The Perl Philosophy
There's more than one way to do it
A correct Perl program...
Three virtues of a programmer
Three more virtues
Share and enjoy!
Parts of Perl
The Perl interpreter
Manuals
Perl Modules
Chapter summary
3. Creating and running a Perl program
In this chapter...
Logging into your account
Using perldoc
Using the editor
Our first Perl program
Running a Perl program from the command line
The "shebang" line
Comments
Command line options
Chapter summary
4. Perl variables
In this chapter...
What is a variable?
Variable names
Variable scoping and the strict pragma
Arguments in favour of strictness
Arguments against strictness
Using the strict pragma
Scalars
Double and single quotes
Exercises
Arrays
A quick look at context
What's the difference between a list and an array?
Exercises
Advanced exercises
Hashes
Initialising a hash
Reading hash values
Adding new hash elements
Other things about hashes
What's the difference between a hash and an associative array?
Exercises
Special variables
The first special variable, $_
@ARGV - a special array
%ENV - a special hash
Chapter summary
5. Operators and functions
In this chapter...
What are operators and functions?
Operators
Arithmetic operators
String operators
Exercises
File operators
Other operators
Functions
Types of arguments
Return values
More about context
Some easy functions
String manipulation
Numeric functions
Type conversions
Manipulating lists and arrays
Hash processing
Reading and writing files
Time
Exercises
Chapter summary
6. Conditional constructs
In this chapter...
What is a block?
Scope
What is a conditional statement?
What is truth?
Comparison operators
Existence and Defined-ness
Boolean logic operators
Using boolean logic operators as short circuit operators
Types of conditional constructs
if statements
while loops
for and foreach
Exercises
Practical uses of while loops: taking input from STDIN
Named blocks
Breaking out of loops
Chapter summary
7. Subroutines
In this chapter...
Introducing subroutines
Calling a subroutine
Passing arguments to a subroutine
Returning values from a subroutine
Exercises
Chapter summary
8. Regular expressions
In this chapter...
What are regular expressions?
Regular expression operators and functions
m/PATTERN/ - the match operator
s/PATTERN/REPLACEMENT/ - the substitution operator
Binding operators
Metacharacters
Some easy metacharacters
Quantifiers
Greediness
Exercises
Grouping techniques
Character classes
Alternation
The concept of atoms
Exercises
Chapter summary
9. Practical exercises
10. Conclusion
What you've learnt
Where to now?
Further reading
A. Unix cheat sheet
B. Editor cheat sheet
vi
Running
Using
Exiting
Gotchas
Help
pico
Running
Using
Exiting
Gotchas
Help
joe
Running
Using
Exiting
Gotchas
Help
jed
Running
Using
Exiting
Gotchas
Help
C. ASCII Pronunciation Guide