Gift Guide

Learning Perl

( 22 )


If you're just getting started with Perl, this is the book you want—whether you're a programmer, system administrator, or web hacker. Nicknamed "the Llama" by two generations of users, this bestseller closely follows the popular introductory Perl course taught by the authors since 1991. This 6th edition covers recent changes to the language up to version 5.14.

Perl is suitable for almost any task on almost any platform, from short fixes to complete web applications. Learning ...

See more details below
Paperback (Sixth Edition)
$29.99 price
(Save 25%)$39.99 List Price

Pick Up In Store

Reserve and pick up in 60 minutes at your local store

Other sellers (Paperback)
  • All (20) from $16.49   
  • New (13) from $22.26   
  • Used (7) from $16.49   
Learning Perl

Available on NOOK devices and apps  
  • NOOK Devices
  • Samsung Galaxy Tab 4 NOOK 7.0
  • Samsung Galaxy Tab 4 NOOK 10.1
  • NOOK HD Tablet
  • NOOK HD+ Tablet
  • NOOK eReaders
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$17.99 price
(Save 43%)$31.99 List Price


If you're just getting started with Perl, this is the book you want—whether you're a programmer, system administrator, or web hacker. Nicknamed "the Llama" by two generations of users, this bestseller closely follows the popular introductory Perl course taught by the authors since 1991. This 6th edition covers recent changes to the language up to version 5.14.

Perl is suitable for almost any task on almost any platform, from short fixes to complete web applications. Learning Perl teaches you the basics and shows you how to write programs up to 128 lines long—roughly the size of 90% of the Perl programs in use today. Each chapter includes exercises to help you practice what you've just learned. Other books may teach you to program in Perl, but this book will turn you into a Perl programmer.

Topics include:

  • Perl data and variable types
  • Subroutines
  • File operations
  • Regular expressions
  • String manipulation (including Unicode)
  • Lists and sorting
  • Process management
  • Smart matching
  • Use of third party modules

The most popular introductory Perl language tutorial has been revised to include CGI scripting and updated to Perl 5.004. Introduces the Perl environment then focuses on the syntax and structure of the language itself. Explains scalar data concepts, lists, arrays and control structures. Clarifies hashes, shows how to use functions, regular expressions and pass arguments. This is also a guide through file handles, file tests, formats and fieldholders. Covers topics on file and directory manipulation, process management, data transformation and database access. Concludes with a good introduction to CGI scripting in preparation for advanced Perl topics. Text is well organized and topics are clearly explained. Exercises, questions and solutions are in the publication, along with supplementary material online.

Read More Show Less

Editorial Reviews

From Barnes & Noble
The Barnes & Noble Review
Want to learn Perl? Any Perlmonger will tell you where to start -- with “the Llama book,” Learning Perl. Now’s the time: It’s just been thoroughly updated for Perl 5.8 and reorganized to be even more effective at teaching Perl novices.

No introductory guide can cover all of Perl, but Learning Perl cover all you need to get seriously productive: scalar data, lists, arrays, subroutines, I/O, hashes, control structures, strings, sorting, processes, and more. This edition’s additions include a new chapter on Perl’s invaluable CPAN archive, plus significantly improved coverage of regular expressions.

Learning Perl’s exercises have been refined through live instruction to thousands of students; they’re truly worth your time. They’ll go a long way towards helping you achieve this book’s core goal: not just to teach you Perl but to transform you into a Perl programmer. Bill Camarda, from the September 2005 Read Only

A hands-on tutorial featuring exercises and complete solutions, covering basics rather than advanced issues. Contents include Perl basics, the language's broad capabilities, brief code examples, system commands, and how to manage DBM databases using Perl. This second edition contains a new chapter on CGI programming. Annotation c. by Book News, Inc., Portland, Or.
Read More Show Less

Product Details

  • ISBN-13: 9781449303587
  • Publisher: O'Reilly Media, Incorporated
  • Publication date: 7/1/2011
  • Edition description: Sixth Edition
  • Edition number: 6
  • Pages: 388
  • Sales rank: 144,484
  • Product dimensions: 7.00 (w) x 9.20 (h) x 1.00 (d)

Meet the Author

Randal L. Schwartz is a two-decade veteran of the software industry. He is skilled in software design, system administration, security, technical writing, and training. Randal has coauthored the "must-have" standards: Programming Perl, Learning Perl, Learning Perl for Win32 Systems, and Effective Perl Learning, and is a regular columnist for WebTechniques, PerformanceComputing, SysAdmin, and Linux magazines.

He is also a frequent contributor to the Perl newsgroups, and has moderated comp.lang.perl.announce since its inception. His offbeat humor and technical mastery have reached legendary proportions worldwide (but he probably started some of those legends himself). Randal's desire to give back to the Perl community inspired him to help create and provide initial funding for The Perl Institute. He is also a founding board member of the Perl Mongers (, the worldwide Perl grassroots advocacy organization. Since 1985, Randal has owned and operated Stonehenge Consulting Services, Inc. Randal can be reached for comment at or (503) 777-0095, and welcomes questions on Perl and other related topics.

brian d foy is a prolific Perl trainer and writer, and runs The Perl Review to help people use and understand Perl through educational, consulting, code review, and more. He's a frequent speaker at Perl conferences. He's the co-author of Learning Perl, Intermediate Perl, and Effective Perl Programming, and the author of Mastering Perl. He was been an instructor and author for Stonehenge Consulting Services from 1998 to 2009, a Perl user since he was a physics graduate student, and a die-hard Mac user since he first owned a computer. He founded the first Perl user group, the New York Perl Mongers, as well as the Perl advocacy nonprofit Perl Mongers, Inc., which helped form more than 200 Perl user groups across the globe. He maintains the perlfaq portions of the core Perl documentation, several modules on CPAN, and some stand-alone scripts.

Tom Phoenix has been working in the field of education since 1982. After more than thirteen years of dissections, explosions, work with interesting animals, and high-voltage sparks during his work at a science museum, he started teaching Perl classes for Stonehenge Consulting Services, where he's worked since 1996. Since then, he has traveled to many interesting locations, so you might see him soon at a Perl Mongers' meeting. When he has time, he answers questions on Usenet's comp.lang.perl.misc and comp.lang.perl.moderated newsgroups, and contributes to the development and usefulness of Perl. Besides his work with Perl, Perl hackers, and related topics, Tom spends his time on amateur cryptography and speaking Esperanto. His home is in Portland, Oregon.

Read More Show Less

Read an Excerpt

Chapter 4: Subroutines

System and User Functions

We've already seen and used some of the builtin system functions, such as chomp, reverse, print, and so on. But, as other languages do, Perl has the ability to make subroutines, which are user-defined functions.1 These let us recycle one chunk of code many times in one program.2

The name of a subroutine is another Perl identifier (letters, digits, and underscores, but can't start with a digit) with a sometimes-optional ampersand (&) in front. There's a rule about when you can omit the ampersand and when you cannot; we'll see that rule by the end of the chapter. For now, we'll just use it every time that it's not forbidden, which is always a safe rule. And we'll tell you every place where it's forbidden, of course.

That subroutine name comes from a separate namespace, so Perl won't be confused if you have a subroutine called &fred and a scalar called $fred in the same program--although there's no reason to do that under normal circumstances.

Defining a Subroutine

To define your own subroutine, use the keyword sub, the name of the subroutine (without the ampersand), then the indented3 block of code (in curly braces) which makes up the body of the subroutine, something like this:

sub marine {
 $n += 1;  # Global variable $n
 print "Hello, sailor number $n!\n";


Subroutine definitions can be anywhere in your program text, but programmers who come from a background of languages like C or Pascal like to put them at the start of the file. Others may prefer to put them at the end of the file, so that the main part of the program appears at the beginning. It's up to you. In any case, you don't normally need any kind of forward declaration.4

Subroutine definitions are global; without some powerful trickiness, there are no private subroutines.5 If you have two subroutine definitions with the same name, the later one overwrites the earlier one.6 That's generally considered bad form, or the sign of a confused maintenance programmer.

As you may have noticed in the previous example, you may use any global variables within the subroutine body. In fact, all of the variables we've seen so far are globals; that is, they are accessible from every part of your program. This horrifies linguistic purists, but the Perl development team formed an angry mob with torches and ran them out of town years ago. We'll see how to make private variables in the section "Private Variables in Subroutines" later in this chapter.

Invoking a Subroutine

Invoke a subroutine from within any expression by using the subroutine name (with the ampersand):7

&marine;  # says Hello, sailor number 1!

&marine;  # says Hello, sailor number 2!

&marine;  # says Hello, sailor number 3!

&marine;  # says Hello, sailor number 4!

Sometimes, we refer to the invocation as calling the subroutine.

Return Values

The subroutine is always invoked as part of an expression, even if the result of the expression isn't being used. When we invoked &marine earlier, we were calculating the value of the expression containing the invocation, but then throwing away the result.

Many times, we'll call a subroutine and actually do something with the result. This means that we'll be paying attention to the return value of the subroutine. All Perl subroutines have a return value--there's no distinction between those that return values and those that don't. Not all Perl subroutines have a useful return value, however.

Since all Perl subroutines can be called in a way that needs a return value, it'd be a bit wasteful to have to declare special syntax to "return" a particular value for the majority of the cases. So Larry made it simple. Every subroutine is chugging along, calculating values as part of its series of actions. Whatever calculation is last performed in a subroutine is automatically also the return value.

For example, let's define this subroutine:

sub sum_of_fred_and_barney {
 print "Hey, you called the sum_of_fred_and_barney subroutine!\n";
 $fred + $barney;  # That's the return value


The last expression evaluated in the body of this subroutine is the sum of $fred and $barney, so the sum of $fred and $barney will be the return value. Here's that in action:

$fred = 3;

$barney = 4;

$c = &sum_of_fred_and_barney; # $c gets 7

print "\$c is $c.\n";

$d = 3 * &sum_of_fred_and_barney; # $d gets 21

print "\$d is $d.\n";

That code will produce this output:

Hey, you called the sum_of_fred_and_barney subroutine!

$c is 7.

Hey, you called the sum_of_fred_and_barney subroutine!

$d is 21.

That print statement is just a debugging aid, so that we can see that we called the subroutine. You'd take it out when the program is finished. But suppose you added another line to the end of the code, like this:

sub sum_of_fred_and_barney {
 print "Hey, you called the sum_of_fred_and_barney subroutine!\n";
 $fred + $barney;  # That's not really the return value!
 print "Hey, I'm returning a value now!\n"; # Oops!


In this example, the last expression evaluated is not the addition; it's the print statement. Its return value will normally be 1, meaning "printing was successful,"8 but that's not the return value we actually wanted. So be careful when adding additional code to a subroutine to ensure that the last expression evaluated will be the desired return value.

So, what happened to the sum of $fred and $barney in that subroutine? We didn't put it anywhere, so Perl discarded it. If you had requested warnings, Perl (noticing that there's nothing useful about adding two variables and discarding the result) would likely warn you about something like "a useless use of addition in a void context." The term void context is just a fancy of saying that the answer isn't being stored in a variable or used by another function.

"The last expression evaluated" really means the last expression evaluated, rather than the last line of text. For example, this subroutine returns the larger value of $fred or $barney:

sub larger_of_fred_or_barney {
 if ($fred > $barney) {
 } else {


The last expression evaluated is the single $fred or $barney, which becomes the return value. We won't know whether the return value will be $fred or $barney until we see what those variables hold at runtime.

A subroutine can also return a list of values when evaluated in a list context.9 Suppose you wanted to get a range of numbers (as from the range operator, ..), except that you want to be able to count down as well as up. The range operator only counts upwards, but that's easily fixed:

sub list_from_fred_to_barney {
 if ($fred < $barney) {
   # Count upwards from $fred to $barney
 } else {
   # Count downwards from $fred to $barney
   reverse $barney..$fred;


$fred = 11;

$barney = 6;

@c = &list_from_fred_to_barney; # @c gets (11, 10, 9, 8, 7, 6)

In this case, the range operator gives us the list from 6 to 11, then reverse reverses the list, so that it goes from $fred (11) to $barney (6), just as we wanted.

These are all rather trivial examples. It gets better when we can pass values that are different for each invocation into a subroutine instead of relying on global variables. In fact, that's coming right up.


That subroutine called larger_of_fred_or_barney would be much more useful if it didn't force us to use the global variables $fred and $barney. That's because, if we wanted to get the larger value from $wilma and $betty, we currently have to copy those into $fred and $barney before we can use larger_of_fred_or_barney. And if we had something useful in those variables, we'd have to first copy those to other variables, say $save_fred and $save_barney. And then, when we're done with the subroutine, we'd have to copy those back to $fred and $barney again.

Luckily, Perl has subroutine arguments. To pass an argument list to the subroutine, simply place the list expression, in parentheses, after the subroutine invocation, like this:

$n = &max(10, 15);  # This sub call has two parameters

That list is passed to the subroutine; that is, it's made available for the subroutine to use however it needs to. Of course, this list has to be stored into a variable, so the parameter list (another name for the argument list) is automatically assigned to a special array variable named @_ for the duration of the subroutine. The subroutine can access this variable to determine both the number of arguments and the value of those arguments.

So, that means that the first subroutine parameter is stored in $_[0], the second one is stored in $_[1], and so on. But--and here's an important note--these variables have nothing whatsoever to do with the $_ variable, any more than $dino[3] (an element of the @dino array) has to do with $dino (a completely distinct scalar variable). It's just that the parameter list must be stored into some array variable for the subroutine to use it, and Perl uses the array @_ for this purpose.

Now, you could write the subroutine &max to look a little like the subroutine &larger_of_fred_or_barney, but instead of using $a you could use the first subroutine parameter ($_[0]), and instead of using $b, you could use the second subroutine parameter ($_[1]). And so you could end up with code something like this:

sub max {
 # Compare this to &larger_of_fred_or_barney
 if ($_[0] > $_[1]) { 
 } else {


Well, as we said, you could do that. But it's pretty ugly with all of those subscripts, and hard to read, write, check, and debug, too. We'll see a better way in a moment.

There's another problem with this subroutine. The name &max is nice and short, but it doesn't remind us that this subroutine works properly only if called with exactly two parameters:

$n = &max(10, 15, 27);  # Oops!

Excess parameters are ignored--since the subroutine never looks at $_[2], Perl doesn't care whether there's something in there or not. And insufficient parameters are also ignored--you simply get undef if you look beyond the end of the @_ array, as with any other array. We'll see how to make a better &max, which works with any number of parameters, later in this chapter.

The @_ variable is local to the subroutine;10 if there's a global value in @_, it is saved away before the subroutine is invoked and restored to its previous value upon return from the subroutine.[11] This also means that a subroutine can pass arguments to another subroutine without fear of losing its own @_ variable--the nested subroutine invocation gets its own @_ in the same way. Even if the subroutine calls itself recursively, each invocation gets a new @_, so @_ is always the parameter list for the current subroutine invocation.

Private Variables in Subroutines

But if Perl can give us a new @_ for every invocation, can't it give us variables for our own use as well? Of course it can.

By default, all variables in Perl are global variables; that is, they are accessable from every part of the program. But you can create private variables called lexical variables at any time with the my operator:

sub max {
 my($a, $b);       # new, private variables for this block
 ($a, $b) = @_;    # give names to the parameters
 if ($a > $b) { $a } else { $b }


These variables are private (or scoped) to the enclosing block; any other $a or $b is totally unaffected by these two. And that goes the other way, too--no other code can access or modify these private variables, by accident or design.12 So, we could drop this subroutine into any Perl program in the world and know that we wouldn't mess up that program's $a and $b (if any).13

It's also worth pointing out that, inside the if's blocks, there's no semicolon needed after the return value expression. Although Perl allows for the last semicolon in a block to be omitted, in practice that's omitted only when the code is so simple that the block is written in a single line, like the previous ones.

The subroutine in the previous example could be made even simpler. Did you notice that the list ($a, $b) was written twice? That my operator can also be applied to a list of variables enclosed in parentheses, so it's more customary to combine those first two statements in the subroutine...

Read More Show Less

Table of Contents

Typographical Conventions;
Code Examples;
Safari® Books Online;
How to Contact Us;
History of This Book;
Changes from the Previous Edition;
Chapter 1: Introduction;
1.1 Questions and Answers;
1.2 What Does “Perl” Stand For?;
1.3 How Can I Get Perl?;
1.4 How Do I Make a Perl Program?;
1.5 A Whirlwind Tour of Perl;
1.6 Exercises;
Chapter 2: Scalar Data;
2.1 Numbers;
2.2 Strings;
2.3 Perl’s Built-in Warnings;
2.4 Scalar Variables;
2.5 Output with print;
2.6 The if Control Structure;
2.7 Getting User Input;
2.8 The chomp Operator;
2.9 The while Control Structure;
2.10 The undef Value;
2.11 The defined Function;
2.12 Exercises;
Chapter 3: Lists and Arrays;
3.1 Accessing Elements of an Array;
3.2 Special Array Indices;
3.3 List Literals;
3.4 List Assignment;
3.5 Interpolating Arrays into Strings;
3.6 The foreach Control Structure;
3.7 Scalar and List Context;
3.8 <STDIN> in List Context;
3.9 Exercises;
Chapter 4: Subroutines;
4.1 Defining a Subroutine;
4.2 Invoking a Subroutine;
4.3 Return Values;
4.4 Arguments;
4.5 Private Variables in Subroutines;
4.6 Variable-Length Parameter Lists;
4.7 Notes on Lexical (my) Variables;
4.8 The use strict Pragma;
4.9 The return Operator;
4.10 Non-Scalar Return Values;
4.11 Persistent, Private Variables;
4.12 Exercises;
Chapter 5: Input and Output;
5.1 Input from Standard Input;
5.2 Input from the Diamond Operator;
5.3 The Invocation Arguments;
5.4 Output to Standard Output;
5.5 Formatted Output with printf;
5.6 Filehandles;
5.7 Opening a Filehandle;
5.8 Fatal Errors with die;
5.9 Using Filehandles;
5.10 Reopening a Standard Filehandle;
5.11 Output with say;
5.12 Filehandles in a Scalar;
5.13 Exercises;
Chapter 6: Hashes;
6.1 What Is a Hash?;
6.2 Hash Element Access;
6.3 Hash Functions;
6.4 Typical Use of a Hash;
6.5 The %ENV hash;
6.6 Exercises;
Chapter 7: In the World of Regular Expressions;
7.1 What Are Regular Expressions?;
7.2 Using Simple Patterns;
7.3 Character Classes;
7.4 Exercises;
Chapter 8: Matching with Regular Expressions;
8.1 Matches with m//;
8.2 Match Modifiers;
8.3 Anchors;
8.4 The Binding Operator =~;
8.5 Interpolating into Patterns;
8.6 The Match Variables;
8.7 General Quantifiers;
8.8 Precedence;
8.9 A Pattern Test Program;
8.10 Exercises;
Chapter 9: Processing Text with Regular Expressions;
9.1 Substitutions with s///;
9.2 The split Operator;
9.3 The join Function;
9.4 m// in List Context;
9.5 More Powerful Regular Expressions;
9.6 Exercises;
Chapter 10: More Control Structures;
10.1 The unless Control Structure;
10.2 The until Control Structure;
10.3 Expression Modifiers;
10.4 The Naked Block Control Structure;
10.5 The elsif Clause;
10.6 Autoincrement and Autodecrement;
10.7 The for Control Structure;
10.8 Loop Controls;
10.9 The Conditional Operator ?:;
10.10 Logical Operators;
10.11 Exercises;
Chapter 11: Perl Modules;
11.1 Finding Modules;
11.2 Installing Modules;
11.3 Using Simple Modules;
11.4 Exercises;
Chapter 12: File Tests;
12.1 File Test Operators;
12.2 The stat and lstat Functions;
12.3 The localtime Function;
12.4 Bitwise Operators;
12.5 Exercises;
Chapter 13: Directory Operations;
13.1 Moving Around the Directory Tree;
13.2 Globbing;
13.3 An Alternate Syntax for Globbing;
13.4 Directory Handles;
13.5 Recursive Directory Listing;
13.6 Manipulating Files and Directories;
13.7 Removing Files;
13.8 Renaming Files;
13.9 Links and Files;
13.10 Making and Removing Directories;
13.11 Modifying Permissions;
13.12 Changing Ownership;
13.13 Changing Timestamps;
13.14 Exercises;
Chapter 14: Strings and Sorting;
14.1 Finding a Substring with index;
14.2 Manipulating a Substring with substr;
14.3 Formatting Data with sprintf;
14.4 Advanced Sorting;
14.5 Exercises;
Chapter 15: Smart Matching and given-when;
15.1 The Smart Match Operator;
15.2 Smart Match Precedence;
15.3 The given Statement;
15.4 Using when with Many Items;
15.5 Exercises;
Chapter 16: Process Management;
16.1 The system Function;
16.2 The Environment Variables;
16.3 The exec Function;
16.4 Using Backquotes to Capture Output;
16.5 External Processes with IPC::System::Simple;
16.6 Processes as Filehandles;
16.7 Getting Down and Dirty with Fork;
16.8 Sending and Receiving Signals;
16.9 Exercises;
Chapter 17: Some Advanced Perl Techniques;
17.1 Slices;
17.2 Trapping Errors;
17.3 Picking Items from a List with grep;
17.4 Transforming Items from a List with map;
17.5 Fancier List Utilities;
17.6 Exercises;
Exercise Answers;
Answers to Chapter 1 Exercises;
Answers to Chapter 2 Exercises;
Answers to Chapter 3 Exercises;
Answers to Chapter 4 Exercises;
Answers to Chapter 5 Exercises;
Answers to Chapter 6 Exercises;
Answers to Chapter 7 Exercises;
Answers to Chapter 8 Exercises;
Answers to Chapter 9 Exercises;
Answers to Chapter 10 Exercises;
Answer to Chapter 11 Exercises;
Answers to Chapter 12 Exercises;
Answers to Chapter 13 Exercises;
Answers to Chapter 14 Exercises;
Answers to Chapter 15 Exercises;
Answers to Chapter 16 Exercises;
Answer to Chapter 17 Exercises;
Beyond the Llama;
Further Documentation;
Regular Expressions;
Extending Perl’s Functionality;
Other Operators and Functions;
Lists and Arrays;
Bits and Pieces;
Networking and IPC;
Command-Line Options;
Built-in Variables;
Syntax Extensions;
Tied Variables;
Operator Overloading;
Dynamic Loading;
Converting Other Languages to Perl;
Converting find Command Lines to Perl;
Command-Line Options in Your Programs;
Embedded Documentation;
More Ways to Open Filehandles;
Threads and Forking;
Graphical User Interfaces (GUIs);
And More…;
A Unicode Primer;
UTF-8 and Friends;
Getting Everyone to Agree;
Fancy Characters;
Dealing with Unicode in Perl;
Further Reading;

Read More Show Less


Attention, class! Attention! Thank you.

Greetings, aspiring magicians. I hope your summer vacations were enjoyable, if too short. Allow me to be the first to welcome you to the College of Wizardry and, more particularly, to this introductory class in the Magic of Perl. I am not your regular instructor, but Professor Schwartz was unavoidably delayed, and has asked me, as the creator of Perl, to step in today and give a few introductory remarks.

Let's see now. Where to begin? How many of you are taking this course as freshmen? I see. Hmmm, I've seen worse in my days. Occasionally. Very occasionally.

Eh? That was a joke. Really! Ah well. No sense of humor, these freshmen.

Well now, what shall I talk about? There are, of course, any number of things I could talk about. I could take the egotistical approach and talk about myself, elucidating all those quirks of genetics and upbringing that brought me to the place of creating Perl, as well as making a fool of myself in general. That might be entertaining, at least to me.

Or I could talk instead about Professor Schwartz, without whose ongoing efforts the world of Pert would be much impoverished, up to and including the fact that this course of instruction wouldn't exist.

That might be enlightening, though I have the feeling you'll know more of Professor Schwartz by the end of this course than I do.

Or, putting aside all this personal puffery, I could simply talk about Pert itself, which is, after all, the subject of this course.

Or is it? Hmmm...

When the curriculum committee discussed this course, it reached the conclusion that this class isn't so much about Perl asit is about you! This shouldn't be too surprising, because Pert is itself also about you-at least in the abstract. Perl was created for someone like you, by someone like you, with the collaboration of many other someones like you. The Magic of Perl was sewn together, stitch by stitch and swatch by swatch, around the rather peculiar shape of your psyche. if you think Perl is a bit odd, perhaps that's why.

Some computer scientists (the reductionists, in particular) would like to deny it, but people have funny-shaped minds. Mental geography is not linear, and cannot be mapped onto a flat surface without severe distortion. But for the last score years or so, computer reductionists have been first bowing down at the Temple of Orthogonality, then rising up to preach their ideas of ascetic rectitude to any who would listen.

Their fervent but misguided desire was simply to squash your mind to fit their mindset, to smush your patterns of thought into some sort of hyperdimensional flatland. It's a joyless existence, being smushed.

Nevertheless, your native common sense has shown through in spots. You and your conceptual ancestors have transcended the dreary landscape to compose many lovely computer incantations. (Some of which, at times, actually did what you wanted them to.) The most blessed of these incantations were canonized as Standards, because they managed to tap into something mystical and magical, performing the miracle of Doing What You Expect.

What nobody noticed in all the excitement was that the computer reductionists were still busily trying to smush your minds flat, albeit on a slightly higher plane of existence. The decree, therefore, went out (I'm sure you've heard of it) that computer incantations were only allowed to perform one miracle apiece. "Do one thing and do it well" was the rallying cry, and with one stroke, shell programmers were condemned to a life of muttering and counting beads on strings (which in these latter days have come to be known as pipelines).

This was when I made my small contribution to saving the world. I was rolling some of those very beads around in my fingers one day and pondering the hopelessness (and haplessness) of my existence, when it occurred to me that it might be interesting to melt down some of those mystical beads and see what would happen to their Magic if I made a single, slightly larger bead out of them. So I fired up the old Bunsen burner, picked out some of my favorite beads, and let them melt together however they would. And lo! the new Magic was more powerful than the sum of its parts and parcels.

That's odd, thought 1. Why should it be that the Sedulous Bead of Regular Expressions, when bonded together with the Shellacious Bead of Gnostic Interpolation, and the Awkward Bead of Simple Data Typology, should produce more Magic, pound for pound, than they do when strung out on strings? I said to myself, could it be that the beads can exchange power with each other because they no longer have to commune with each other through that skinny little string? Could the pipeline be holding back the flow of information, much as wine doth resist flowing through the neck of Doctor von Neumann's famous bottle?

This demanded (of me) more scrutiny (of it).

So I melted that larger bead together with a few more of my favorite beads, and the same thing happened, only more so. It was practically a combinatorial explosion of potential incantations: the Basic Bead of Output Formats and the Lispery Bead of Dynamic Scoping bonded themselves with the C-rationalized Bead of Operators Galore, and together they put forth a brilliant pulse of power that spread to thousands of machines throughout the entire civilized world. That message cost the Net hundreds if not thousands of dollars to send everywhere. Obviously I was either onto something, or on something.

I then gathered my courage about me and showed my new magical bead to some of you, and you then began to give me your favorite beads to add in as well. The Magic grew yet more powerful, as yet more synergy was imbued in the silly thing. It was as if the Computational Elementals summoned by each bead were cooperating on your behalf to solve your problems for you. Why the sudden peace on earth and good will toward mentality? Perhaps it was because the beads were your favorite beads? Perhaps it was because I'm just a good bead picker?

Perhaps I just got lucky.

Whatever, the magical bead eventually grew into this rather odd-looking Amulet you see before you today. See it glitter, almost like a pearl.

That was another joke. Really! I assure you! Ah well. I was a freshman once too... The Amulet isn't exactly beautiful though; in fact, up close it still looks like a bunch of beads melted together. Well, all right, I admit it. it's downright ugly. But never mind that. It's the Magic that counts. Speaking of Magic, took who just walked in the door! My good buddy Merlyn, er, I should say, Professor Schwartz, is here just in the nick of time to begin telling you how to perform miracles with this little Amulet, if you're willing to learn the proper mysterious incantations. And you're in good hands; I must admit that there's no one better at muttering mysterious incantations than Professor Schwartz. Eh, Merlyn?

Anyway, to sum up. What you'll need most is courage. It is not an easy path that you've set your foot upon. You're learning a new language: a language full of strange runes and ancient chants, some easy and some difficult, many of which sound familiar, and some of which don't. You may be tempted to become discouraged and quit. But think you upon this: consider how long it took you to learn your own native tongue. Was it worth it? I think so. And have you finished learning it? I think not. Then do not expect to learn all the mysteries of Perl in a moment, as though you were consuming a mere peanut, or an olive. Rather, think of it as though you were consuming, say, a banana. Consider how this works. You do not wait to enjoy the banana until after you have eaten the whole thing. No, of course not. You enjoy each bite as you take it. And each bite motivates you to take the next bite, and the next.

So then, speaking now of the fruit of Merlyn's labors, I would urge you to enjoy this, um, course. The fruit course, of course. Ahem, that was a joke too. Ah well.

Here then, Professor, I present to you your new class. They seem to have no sense of humor whatsoever, but I expect you'll manage somehow.

Class, I present to you Professor Randal L. Schwartz, Doctor of Syntax, Wizard at Large, and of course, just Another Perl Hacker. He has my blessings, just as you have my blessings. May you Learn Perl. May you do Good Magic with Perl. And above all, may you have Lots of Fun with Perl. So be it!

So do it!

Read More Show Less

Customer Reviews

Average Rating 4
( 22 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 19 Customer Reviews
  • Posted January 24, 2010

    I Also Recommend:

    A must read for everyone interested in Perl.

    This is the best book for learning Perl, in my opinion. This might not be the best book those who haven't ever programed before though because it focuses more on the syntax of the simple things (like if, while, for, etc.) and expects you know how they work.

    What I liked about this book was all the footnotes. Yes, I know that sounds weird, but there are a lot of footnotes, all with interesting information, like why Larry named things the names he did.

    Overall, this books keeps you interested, and isn't a long boring read.

    2 out of 2 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted November 4, 2005


    If you want to spend some time learning Perl, this fourth edition of the book is for you. Authors Randal Schwartz, Tom Phoenix and brian foy, have done an outstanding job of providing you with a book that helps you understand why the Perl programming language is the workhorse of the Internet as well as, the language of choice for system administrators, web hackers, and casual programmers around the world. Schwartz, Phoenix and foy begin by asking you a number of questions: What does Perl stand for? How can you get Perl? How do you make a Perl program? And, so forth. Next, the authors cover scalar data, with respect to numbers and strings. Then, they examine lists (an ordered collection of scalars) and arrays ( a variable that contains a list). The authors continue by showing you how Perl can make subrountines, which are user-defined functions. In addition, the authors next introduce you to the workings of standard input, output and error streams. They also show you a feature that makes Perl one of the world's great programming languages--hashes. Next, the authors take you on a trip to visit the world of regular expressions, where you can forget about the world of Perl. Then, they show you where this world fits into Perl's world. The authors continue by showing you how to use patterns to locate the parts of strings that you want to change. Then, you'll see some alternative ways to write Perl code. In addition, the authors present a complete set of tests that are used by Perl to help you find information about files. They also show you how Perl lets you manipulate operations directories directly, in ways that are even fairly portable from one operating system to another. Next, the authors show you a simpler way of working with strings and sorting. Then, they present the inner workings of process management. The authors continue by showing you how to use modules that already exist. Finally, they examine some advanced Perl techniques. With the preceding in mind, the authors have done an excellent job of giving you a real whirlwind tour of Perl. So, at the end of the day, you'll know whether this is the right Perl book for you!

    1 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Posted April 25, 2011

    Good book but badly formatted

    Code examples run off the edge of the screen so you cannot read them. Read it in another form because it is worth reading. It is a good intro to Perl from the ground up.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted April 5, 2011

    formatting issue

    constant width text does not reflow properly. this makes the majority of the comments in code examples partially unreadable where they run off the page. content of the book is otherwise great.

    Was this review helpful? Yes  No   Report this review
  • Posted February 13, 2010

    Excellent resource

    This book is an excellent intro to Perl. It will also serve as a reference later on. Highly recommended purchase if you have any interest in Perl

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted April 10, 2009

    excellent introduction


    0 out of 1 people found this review helpful.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted June 18, 2008

    Easy to understand, thorough method.

    This is a wonderful book for any beginner to Perl. I'd had no previous experience, and I've found the exercises to be easy and educational. The authors have good senses of humor and the writing style is excellent. Overall, 'Learning Perl' is a must-have for all beginning Perl students.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted July 29, 2009

    No text was provided for this review.

  • Anonymous

    Posted October 3, 2010

    No text was provided for this review.

  • Anonymous

    Posted April 22, 2011

    No text was provided for this review.

  • Anonymous

    Posted October 14, 2008

    No text was provided for this review.

  • Anonymous

    Posted February 26, 2009

    No text was provided for this review.

  • Anonymous

    Posted November 9, 2009

    No text was provided for this review.

  • Anonymous

    Posted September 19, 2010

    No text was provided for this review.

  • Anonymous

    Posted August 10, 2011

    No text was provided for this review.

  • Anonymous

    Posted March 27, 2010

    No text was provided for this review.

  • Anonymous

    Posted October 14, 2009

    No text was provided for this review.

  • Anonymous

    Posted November 6, 2008

    No text was provided for this review.

  • Anonymous

    Posted February 22, 2010

    No text was provided for this review.

Sort by: Showing all of 19 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)