Learning Perl
Randal L. Schwartz & Tom Phoenix

This page:

Learning Perl


computer programming

index pages:

Learning Perl
Third Edition
Randal L. Schwartz & Tom Phoenix

Copyright © 2001, 1997, 1993, by O’Reilly & Associates, Inc.

Note (Hal’s):
This is far more enjoyable than most texts. Many of these amusing items were lurking in the footnotes.

Beyond the material in the text, programmers may be especially interested in the implications of Randal Schwartz’s legal troubles. See for an eye-opening story.

— end note

Chapter 1 Introduction
What Does “Perl” Stand For?
Is Perl Easy or Hard?
  [...] the number of bugs in a program is roughly proportional to the length of the source code* (rather than being proportional to the program’s functionality) [...]

* With a sharp jump when any one section of the program exceeds the size of your screen.



What Is Perl Not Good For?
The real way to keep your secret algorithm a secret is, alas, to apply the proper number of attorneys; they can write a license that says “you can do this with the code, but you can’t do that. And if you break our rules, we’ve got the proper number of attorneys to ensure that you’ll regret it.”




How Can I Get Perl?
How Can I Get Support for Perl?
[...] it’s a program, and every program has at least one bug.*

* Programmers also know that every program has at least one line of unnecessary source code. By combining these two rules and using logical induction, it’s a simple matter to prove that any program could be reduced to a single line of code with a bug.


Logic (examples)

Chapter 3 Lists and Arrays
List Assignment
The pop and push Operators
Occasionally, a beginning Perl programmer (wanting to see how Perl’s speed compares to C’s) will take, say, a sorting algorithm optimized for C (with many array index operations), rewrite it straightforward in Perl (again, with many index operations) and wonder why it’s so slow. The answer is that using a Stradivarius violin to pound nails should not be considered a sound construction technique.


Computer programming

Chapter 4 Subroutines
System and User Functions

The code examples used in this book are recycled from at least 40% post-consumer programming, and are at least 75% recyclable into your programs when properly decomposed.

Chapter 8 More About Regular Expressions
Word Anchors
And even in text that may be mostly ordinary English, it’s normal to find a soupçon of other characters spicing things up.
Chapter 10 More Control Structures
The elsif Clause

You may have noticed by this point that the keyword is spelled elsif, with only one e. If you write it as “elseif”, with a second e, Perl will tell you that it is not the correct spelling. Why not? Because Larry says so.†

† In fact, he resists any suggestion that it even be permitted as a valid alternative spelling. “If you want to spell it with a second e, it’s simple. Step 1—Make up your own language. Step 2—Make it popular.”

The for Control Structure
The Secret Connection Between foreach and for
Among programmers, especially Perl programmers, laziness is one of the classical virtues.



It’s easy to get a so-called “fencepost” bug with this kind of loop, like what happened when the rancher needed enough fenceposts to make a 30-meter-long fence with a post every three meters. (The answer is not ten fenceposts.)
Chapter 13 Manipulating Files and Directories
Renaming Files

This isn’t just any old frequent question; the question of renaming a batch of files at once is the most-frequent question asked in these newsgroups. And that’s why it’s the first question answered in the FAQs for those newsgroups. And yet, it stays in first place. Hmmm.

Chapter 17 Some Advanced Perl Techniques
Hash Slice

If it sounds as if we’re repeating ourselves here, it’s because we want to emphasize that hash slices are analogous to array slices. If it sounds as if we’re not repeating ourselves here, it’s because we want to emphasize that hash slices are analogous to array slices.

A hash slice is a slice (not a hash) in the same way that a house fire is a fire (not a house), while a fire house is a house (not a fire). More or less.

text checked (see note) Feb 2005

top of page

Background graphic copyright © 2003 by Hal Keen