Perl 5 Interactive Course
(Publisher: Macmillan Computer Publishing)
Author(s): JON ORWANT
ISBN: 1571690646
Publication Date: 08/30/96

Introduction
Preface
About the Author

CHAPTER 1—MEET PERL: THE BASICS
Session 1—The Look and Feel of Perl
Running a Perl Program
Command-Line Flags
Is Perl Compiled or Interpreted?
Quiz 1
Exercise 1
Session 2—Scalars
Double Quotes and Single Quotes
Functions
The chomp() and chop() Functions
Operators
Quiz 2
Exercise 2
Session 3—The if Statement and Expressions
Expressions
Backslashed Characters
if...else Statements
Assignment Operators
Exponentiation
Precedence
Autoincrement and Autodecrement
The ?: Operator
The ! Operator
Quiz 3
Exercise 3
Session 4—Introduction to Loops
Beware Infinite Loops!
The % Operator
The int() Function
Rounding Numbers
Integer Arithmetic
Quiz 4
Exercise 4
Review
Session 5—Arrays
The foreach Loop
Array Indexing
A Few Words About Initial Characters
Out of Bounds!
The Last Index of an Array
The $[ Special Variable
Negative Array Indexes
Adding and Removing Array Elements
push() and pop()
unshift() and shift()
splice()
Quiz 5
Exercise 5
Session 6—Advanced Loops
The for Loop
Loop Control: next, last, andredo
Ssssshhhhh!
Quiz 6
Exercise 6
Session 7—The Default Variable $_
@ARGV
Quiz 7
Exercise 7
Session 8—Contexts
The scalar() Function
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Difficult

CHAPTER 2—PATTERN MATCHING: REGULAR EXPRESSIONS
Session 1—Regular Expressions
Making Substitutions
Alternatives
The -n and -p Command-Line Flags
Quiz 1
Exercise 1
Session 2—Metacharacters And Special Characters
Kleene Plus: +
Kleene Star: *
Curly Braces
Question Marks
The . Special Character
Quiz 2
Exercise 2
Session 3—Matching
Parentheses
QUIZ 3
Exercise 3
Session 4—Translations
Quiz 4
Exercise 4
Review
Session 5—Pattern Anchors and Some More Special Variables
Quiz 5
Exercise 5
Session 6—Advanced regexes I and grep()
Ranges
grep()
Quiz 6
Exercise 6
Session 7—map() and Advanced Regexes II
map()
Greediness
Uncluttering regexes
Quiz 7
Exercise 7
Session 8—Advanced regexes III
Regexp Extensions
study()
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Moderate
Medium
Hard

CHAPTER 3—THE OUTSIDE WORLD: FILES AND FILEHANDLES
Session 1—Introduction to I/O
Filehandles
Standard Filehandles
Reading from a File
Exiting a Program
Logical Operators
The $! Special Variable
Writing to a File
In-Place Editing
Quiz 1
Exercise 1
Session 2—Reading and Writing
Moving Around in a File
Shortening Files
Quiz 2
Exercise 2
Session 3—External Programs and Pipes
Backquotes
system()
Executing Another Perl Program
Piping Data to and from a Program
Pipe Errors
Deleting Files
Quiz 3
Exercise 3
Session 4—Interacting with UNIX
Links
File Locking
UNIX Permissions
utime()
Quiz 4
Exercise 4
Review
Session 5—Using Internet Applications
Generating E-Mail from Your Perl Programs
Filtering Incoming E-Mail
Using an Internet Service
Quiz 5
Exercise 5
Session 6—Inspecting Files
_, stat(), and file tests
Quiz 6
Exercise 6
Session 7—File Bits and Bytes
Testing for “End of File”
Reading Bytes Instead of Lines
Buffering
Quiz 7
Exercise 7
Session 8—Accessing Directories
Accessing Directories
Making (and Unmaking) Directories
Changing Directories
Globbing
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard

CHAPTER 4—DIVIDE AND CONQUER: SUBROUTINES
Session 1—Introduction To Subroutines
Invoking Subroutines
Subroutine Output
Quiz 1
Exercise 1
Session 2—Argument Passing And Some Math
A Bit of Math: sqrt() and abs()
Exponential Notation
Quiz 2
Exercise 2
Session 3—Recursion And More Math
Recursion
sin(), cos(), and atan2()
exp() and log()
Quiz 3
Exercise 3
Session 4—Scoping
Quiz 4
Exercise 4
Review
Session 5—Blocks
Labels
goto
do()…until()
Continue Blocks
reset()
??
Quiz 5
Exercise 5
Session 6—Organizing Arrays And Autoloading Functions
Sorting
The <=> and cmp Operators
Joining Arrays and Splitting Strings
Array Interpolation
Reversing Variables
Autoloading
Quiz 6
Exercise 6
Section 7—Arrays And Subroutines
Passing Multiple Arrays into a Subroutine
Passing References
Passing Globs
Modifying Subroutine Arguments
Passing a Filehandle into a Subroutine
wantarray()
Quiz 7
Exercise 7
Session 8—Bits and Bases
chr(), ord(), oct(), and hex()
Bitwise Operators
vec()
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard

CHAPTER 5—MINCING WORDS: HASHES
Session 1—What’s a Hash?
Quiz 1
Exercise 1
Session 2—Manipulating Keys and Values
Retrieving Keys or Values
Retrieving Keys and Values
Deleting Key-Value Pairs
Quiz 2
Exercise 2
Session 3—Randomness and Time
Choosing a Random Number
Time
Quiz 3
Exercise 3
Session 4—%Env and Sleeping
Sleeping
Quiz 4
Exercise 4
Review
Session 5—Existence
Quiz 5
Exercise 5
Session 6—Data Structures
User-Defined Data Types
Anonymous Variables
Multielement Keys
The Perl Data Structures Cookbook
Quiz 6
Exercise 6
Session 7—Hash Leftovers
Hash Storage Efficiency
Hashes as Subroutine Arguments
Symbol Tables
Sorting a Hash
Quiz 7
Exercise 7
Session 8—Quoting Operators and Barewords
q, qq, and qx
qw()
quotemeta()
Barewords
Quiz 8
Exercise 8
Chapter Exercise
Easy
Medium
Moderate
Hard
Review

CHAPTER 6—LOOKS ARE EVERYTHING: FORMATS
Session 1—Introduction To Formats
Declaring Formats
Naming Formats
Formatting Without Formats
Quiz 1
Exercise 1
Session 2—Picture Fields
Aligning Variables
Quiz 2
Exercise 2
Session 3—Pages
Headers
Pagination
Lines on a Page and Footers
Quiz 3
Exercise 3
Session 4—Formatted Strings
Printing a Formatted String
Creating a Formatted String
Record Separators
The Input Record Separator
The Output Record Separator
Field and List Separators
Quiz 4
Exercise 4
Review
Session 5—Here Strings And Special Literals
Here Strings
Special Literals
Quiz 5
Exercise 5
Session 6—Advanced Formats
Multiline Picture Fields
Accessing Your Formatted Data Without Printing
Quiz 6
Exercise 6
Session 7—Generating PostScript
The PostScript Page Description Language
PostScript Headers and Footers
Drawing Lines
Drawing Text
Circles, Squares, and Fills
Quiz 7
Exercise 7
Session 8—Binary Data
Binary Data
TIFF
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard

CHAPTER 7—hOOPla: OBJECT-ORIENTED PROGRAMMING
Session 1—OOP and Packages
Object-Oriented Programming
Encapsulation
Inheritance
Polymorphism
Packages
Quiz 1
Exercise 1
Session 2—References
Creating and Accessing References
A Word About Syntax
The ref() Function
Copying References vs. Copying Values
Symbolic References vs. Hard References
Quiz 2
Exercise 2
Session 3—Anonymous Variables and Objects
Anonymous Variables (and Anonymous Functions)
Omitting ->
Anonymous Subroutines and Closures
Creating Objects
Quiz 3
Exercise 3
Session 4—Methods
Static vs. Virtual Methods
Passing Arguments to Methods
Quiz 4
Exercise 4
Review
Session 5—Inheritance
Choosing a Base Class
Inheritance: Where Does It End?
Multiple Inheritance
Inheriting Variables
Quiz 5
Exercise 5
Session 6—Advanced OOP Features
Subpackages
Access to Overridden Methods
Destructors
Reblessing Objects
Quiz 6
Exercise 6
Session 7—OOP Design Methods
A Containing Relationship
Calling the Right Method
Class Variables
Quiz 7
Exercise 7
Session 8—Overloading
%OVERLOAD
Input Arrays for Overloaded Functions
Overloadable Operations
$OVERLOAD{nomethod}
Autogeneration of Functions
$OVERLOAD{fallback}
$OVERLOAD{‘=’}
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard

CHAPTER 8—BROWSING THE LIBRARY: MODULES
Session 1—The Perl Library
Library Files
Modules
Pragmas
The integer Pragma
The subs Pragma
Prototypes
The strict Pragma
Other Pragmas
Quiz 1
Exercise 1
Session 2—English, Time, Syslog, and POD
English
English
Time
Time::Local
Syslog
Sys::Syslog
POD: Plain Old Documentation
Quiz 2
Exercise 2
Session 3—Making Modules
Exporter
AutoLoader
AutoSplit
Quiz 3
Exercise 3
Session 4—Getopt and Assert
Getopt
Getopt::Std
Getopt::Long
Assert
assert.pl
Quiz 4
Exercise 4
Review
Session 5—Inspecting and Testing
Config
Config
Env
Env
Cwd
Cwd
Benchmark
Benchmark
Sys
Sys::Hostname
Dumpvar
dumpvar.pl
Quiz 5
Exercise 5
Session 6—Files
File
File::Find
File::Finddepth
File::Checktree
File::Basename
FileHandle
FileHandle
Flush
flush.pl
Stat
stat.pl
Quiz 6
Exercise 6
Session 7—Text, Search, and Math
Text
text::abbrev
Text::Soundex
Text::Tabs
Text::ParseWords
Search
Search::Dict
Math
Math::BigInt
Math::BigFloat
bigrat.pl
Math::Complex
Quiz 7
Exercise 7
Session 8—Dotsh.pl, Term, and Posix
dotsh.pl
dotsh.pl
Term
Term::Cap
Term::Complete
POSIX
POSIX
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard

CHAPTER 9—PUSHING THE ENVELOPE: PROCESS MANAGEMENT
Session 1—Eval()
Trapping Fatal Errors
Assembling Functions
Quiz 1
Exercise 1
Session 2—Signals
Trapping Signals
$SIG{__WARN__} and $SIG{__DIE__}
The sigtrap Pragma
Sending Signals
Alarm
Quiz 2
Exercise 2
Session 3—Exec() And Fork()
exec()
Special Characters in Perl vs. Special Characters in UNIX Shells
Forking Processes
Quiz 3
Exercise 3
Session 4—Process Attributes
Changing the Process Name
Getting the PID of the Parent Process
Process Priorities
Process Groups
Quiz 4
Exercise 4
Review
Session 5—Wait(), Pipe(), Open2, And Open3
Waiting for Another Process to Finish
What’s a Blocking Operation?
Pipes
Open2 and Open3
Quiz 5
Exercise 5
Session 6—Advanced I/O
select()
File Control with fcntl()
I/O Control with ioctl()
Term::ReadKey
Term::ReadLine
Quiz 6
Exercise 6
Session 7—Syscall() And Compiling Perl
System Calls
Compiling Perl
The Perl Compiler
Quiz 7
Exercise 7
Session 8—System V Interprocess Communication
Message Queues
Semaphores
Shared Memory
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard

CHAPTER 10—WHEN GOOD PROGRAMS GO BAD: DEBUGGING
Session 1—How To Fix It
Warnings
Checking Syntax
Diagnostics
Bugs in Perl
Quiz 1
Exercise 1
Session 2—Perl Pitfalls
Lists vs. Scalars
Functions Seek Out Argument Lists
Functions
Syntax and Logic
Operators
Regular Expressions
Precedence
Scoping
Sorting
Quiz 2
Exercise 2
Session 3—Error Messages
Array Found Where Operator Expected
Can’t Bless Non-Reference Value
Can’t Coerce…
Can’t Find String Terminator
Can’t Locate…
Can’t Locate…
Can’t Modify Constant Item…
Can’t Return Outside a Subroutine
Can’t Write to Temp File for -e
Deep Recursion on Subroutine
…Follows Nothing in regexp
INFINITE LOOP 1 (Not an Actual Error Message)
INFINITE LOOP 2 (Not an Actual Error Message)
INFINITE LOOP 3 (Not an Actual Error Message)
INFINITE LOOP 4 (Not an Actual Error Message)
INFINITE LOOP 5 (Not an Actual Error Message)
Literal Array Now Requires Backslash at Program Line 2, Within String
Modification of a Read-Only Value
Nested *?+ in regexp
Not Enough Arguments
Number Found Where Operator Expected
…Permission Denied
Precedence Problem
Recompile Perl with -DDEBUGGING to Use -D Switch
Sort Subroutine Didn’t Return a Numeric Value
substr Outside of String
Syntax Error…
Type of arg to Keys Must Be Hash
Undefined sort Subroutine…
Undefined Subroutine…
…Unmatched [] in regexp
Unquoted String May Clash with Future Reserved Word
Use of Uninitialized Value
Use of … Is Deprecated
Useless Use…
Quiz 3
Exercise 3
Session 4—Using the Debugger
Quiz 4
Exercise 4
Review
Session 5—Advanced Debugging
Quiz 5
Exercise 5
Session 6—-Ddebugging
Quiz 6
Exercise 6
Session 7—Error Handling
Caller
Exceptions
Carp
Quiz 7
Exercise 7
Session 8—Efficiency
Minimizing Time
Easy Choices
Hard Choices
Minimizing Space
Easy Choices
Hard Choices
Profiling Your Code
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard

CHAPTER 11—LOCK AND KEY: SECURITY AND DATABASES
Session 1—Unix Users and Groups
Quiz 1
Exercise 1
Session 2—Unix Setuid Scripts and the Safe module
Real vs. Effective UIDs
setuid Bits
Tainted Variables
The Safe Module
Quiz 2
Exercise 2
Session 3—Encryption
crypt()
DES
RSA
Quiz 3
Exercise 3
Session 4—Tied Variables
Quiz 4
Exercise 4
Review
Session 5—Database Modules
Quiz 5
Exercise 5
Session 6—DBI, the Database Interface
Using DBI
DBI Methods
Quiz 6
Exercise 6
Session 7—Non-DBI Interfaces, Part I
Oracle
Sybase
Informix
Ingres
Quiz 7
Exercise 7
Session 8—Non-DBI Interfaces, Part II
Interbase
UNIFY
Postgres
C-Tree
C-ISAM
X.500
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard

CHAPTER 12—SURFING ON OYSTERS: PERL AND THE WORLD WIDE WEB
Session 1—A World Wide Web Primer
HTML
Links and URLs
Quiz 1
Exercise 1
Session 2—Generating WWW Pages
CGI
Getting CGI to Find Your Perl Scripts
Quiz 2
Exercise 2
Session 3—HTML Forms
Radio Buttons
Checkboxes
<SELECT>
<TEXTAREA>
Quiz 3
Exercise 3
Session 4—Images, Audio, and Video
Images
Audio, Video, and Noninlined Images
Quiz 4
Exercise 4
Review
Session 5—Perl/Web Resources
perlWWW
CGI.pm
libwww-perl
The CGI Module Set
The URI Module Set
The HTTP Module Set
The HTML Module Set
The WWW Module Set
The MIME Module Set
The LWP Module Set
Quiz 5
Exercise 5
Session 6—Running a WWW Server
Plexus
phttpd
Quiz 6
Exercise 6
Session 7—Advanced Webbery
Security
Netscape, SSL, and HTTPS
Firewalls
Dynamic Documents
Java
Penguin
Server Push and Client Pull
Weblint, htmlchek, linkcheck, and verify_links
Weblint
htmlchek
linkcheck
verify_links
webget and url_get
webget
url_get
Mail
MHonArc
Hypermail
Quiz 7
Exercise 7
Session 8—Non-Web Internet Services
FTP
IRC
WAIS
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard

CHAPTER 13—SPREADING THE WORD: NETWORKING
Session 1—How the Internet Works
Protocol Layers
Ports
Quiz 1
Exercise 1
Session 2—Networking Utilities
rsh
comm.pl and chat2.pl
inetd
Quiz2
Exercise 2
Session 3—Sockets
Quiz 3
Exercise 3
Session 4—Multiuser Services
Quiz 4
Exercise 4
Review
Session 5—Interactive Services
Quiz 5
Exercise 5
Session 6—Bulletproofing Servers
Zombie Processes
Reusing Local Addresses
Server Exclusivity
Quiz 6
Exercise 6
Session 7—Advanced Sockets
Using socketpair() to Create a Two-Way Pipe
Socket Addresses
Socket Control
shutdown()
send() and recv()
Quiz 7
Exercise 7
Session 8—Network Databases
Hosts
Services
Protocols
Networks
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard

CHAPTER 14—TOWER OF BABEL: PERL AND OTHER LANGUAGES
Session 1—X
Tcl, Tk, X: What’s the Difference?
General Perl/Tk Information
Simple Tk Programs
Quiz 1
Exercise 1
Session 2—More X
Text Widgets and Dialog Boxes
Animation
Tk Utilities
Quiz 2
Exercise 2
Session 3—Curses
Quiz 3
Exercise 3
Session 4—Awk, Sed, and Find
awk
sed
find
Quiz 4
Exercise 4
Review
Session 5—Using C from Perl
The Perl Compiler
The C Preprocessor
Source Filtering
Using C Functions and Libraries
Extensions
XS
Linking a C Function into Perl
Linking a C Library into Perl
Quiz 5
Exercise 5
Session 6—Advanced XS
Modifying Input Arguments and Passing Strings to an XSUB
Multiple XSUBs
The CODE: keyword
Types and the typemap
Quiz 6
Exercise 6
Session 7—Using Perl from C
Quiz 7
Exercise 7
Session 8—Using the Perl Stack from C
Playing with the Stack
The perl_call_ Functions
Quiz 8
Exercise 8
Review
Chapter Exercise
Easy
Medium
Moderate
Hard
Appendix A
Appendix B
Appendix C
Appendix D
Appendix E
Appendix F
Appendix G
Appendix H
Appendix I
Appendix J
Appendix K
Index