What’s New in This Edition

What’s not new? It’s been a long time since we’ve updated this book. Let’s just say we had a couple of distractions, but we’re all better now.

The third edition was published in the middle of 2000, just as Perl v5.6 was coming out. As we write this, it’s 12 years later and Perl v5.16 is coming out soon. A lot has happened in those years, including several new releases of Perl 5, and a little thing we call Perl 6. That 6 is deceptive though; Perl 6 is really a “kid sister” language to Perl 5, and not just a major update to Perl 5 that version numbers have trained you to expect. This book isn’t about that other language. It’s still about Perl 5, the version that most people in the world (even the Perl 6 folks!) are still using quite productively.[1]

To tell you what’s new in this book is to tell you what’s new in Perl. This isn’t just a facelift to spike book sales. It’s a long anticipated major update for a language that’s been very active in the past five years. We won’t list everything that’s changed (you can read the perldelta pages), but there are some things we’d like to call out specifically.

In Perl 5, we started adding major new features, along with a way to shield older programs from new keywords. For instance, we finally relented to popular demand for a switch-like statement. In typical Perl fashion, though, we made it better and more fancy, giving you more control to do what you need to do. We call it given–when, but you only get that feature if you ask for it. Any of these statements enable the feature:

use v5.10;
use feature qw(switch);
use feature qw(:5.10);

and once enabled, you have your super-charged switch:

given ($item) {
  when (/a/)   { say "Matched an a"  }
  when (/bee/) { say "Matched a bee" }

You’ll see more about that in Chapter 4, along with many of the other new features as they appear where they make the most sense.

Although Perl has had Unicode support since v5.6, that support is greatly improved in recent versions, including better regular expression support than any other language at the moment. Perl’s better-and-better support is even acting as a testbed for future Unicode developments. In the previous edition of this book, we had all of that Unicode stuff in one chapter, but you’ll find it throughout this book when we need it.

Regular expressions, the feature that many people associate with Perl, are even better. Other languages stole Perl’s pattern language, calling it Perl Compatible Regular Expressions, but also adding some features of their own. We’ve stolen back some of those features, continuing Perl’s tradition of taking the best ideas from everywhere and everything. You’ll also find powerful new features for dealing with Unicode in patterns.

Threads are much different today, too. Perl used to support two thread models: one we called 5005threads (because that’s when we added them), and interpreter threads. As of v5.10, it’s just the interpreter threads. However, for various reasons, we didn’t think we could do the topic justice in this edition since we dedicated our time to many of the other features. If you want to learn about threads, see the perlthrtut manpage, which is approximately the same thing as our “Threads” chapter would have been. Maybe we can provide a bonus chapter later, though.

Other things have come or gone. Some experiments didn’t work out and we took them out of Perl, replacing them with other experiments. Pseudohashes, for instance, were deprecated, removed, and forgotten. If you don’t know what those are, don’t worry about it, but don’t look for them in this edition either.

And, since we last updated this book, there’s been a tremendous revolution (or two) in Perl programming practice as well as its testing culture. CPAN (the Comprehensive Perl Archive Network) continues to grow exponentially, making it Perl’s killer feature. This isn’t a book about CPAN, though, but we tell you about those modules when they are important. Don’t try to do everything with just vanilla Perl.

We’ve also removed two chapters, the list of modules in the Standard Library (Chapter 32 in the previous edition) and the diagnostic messages (Chapter 33 in the previous edition). Both of these will be out of date before the book even gets on your bookshelf. We’ll show you how to get that list yourself. For the diagnostic messages, you can find all of them in the perldiag manpage, or turn warnings into longer messages with the diagnostics pragma.

Part I, Overview

Getting started is always the hardest part. This part presents the fundamental ideas of Perl in an informal, curl-up-in-your-favorite-chair fashion. Not a full tutorial, it merely offers a quick jump-start, which may not serve everyone. See the section on “Offline Documentation” below for other books that might better suit your learning style.

Part II, The Gory Details

This part consists of an in-depth, no-holds-barred discussion of the guts of the language at every level of abstraction, from data types, variables, and regular expressions, to subroutines, modules, and objects. You’ll gain a good sense of how the language works, and in the process, pick up a few hints on good software design. (And if you’ve never used a language with pattern matching, you’re in for a special treat.)

Part III, Perl As Technology

You can do a lot with Perl all by itself, but this part will take you to a higher level of wizardry. Here you’ll learn how to make Perl jump through whatever hoops your computer sets up for it, everything from dealing with Unicode, interprocess communication and multithreading, through compiling, invoking, debugging, and profiling Perl, on up to writing your own external extensions in C or C++, or interfaces to any existing API you feel like. Perl will be quite happy to talk to any interface on your computer—or, for that matter, on any other computer on the Internet, weather permitting.

Part IV, Perl As Culture

Everyone understands that a culture must have a language, but the Perl community has always understood that a language must have a culture. This part is where we view Perl programming as a human activity, embedded in the real world of people. We’ll cover how you can improve the way you deal with both good people and bad people. We’ll also dispense a great deal of advice on how you can become a better person yourself, and on how to make your programs more useful to other people.

Part V, Reference Material

Here we’ve put together all the chapters in which you might want to look something up alphabetically, everything from special variables and functions to standard modules and pragmas. The Glossary will be particularly helpful to those who are unfamiliar with the jargon of computer science. For example, if you don’t know what the meaning of “pragma” is, you could look it up right now. (If you don’t know what the meaning of “is” is, we can’t help you with that.)

[1] Since we’re lazy, and since by now you already know this book is about Perl 5, we should mention that we won’t always spell out “Perl v5.n”—for the rest of this book, if you see a bare version number that starts with “v5”, just assume we’re talking about that version of Perl.

Get Programming Perl, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.