Preface

Jon Orwant

This is the first of three “Best of the Perl Journal” O’Reilly books, containing the crème de la crème of the 247 articles published during the Perl Journal’s five-year existence as a standalone magazine. This particular book covers computer science topics, advanced Perl programming techniques, and other subjects: together, the 70 articles in this book constitute a compendium of Perl lore. Little of what you’ll find here is covered in any other book.

This book is divided into eight sections:

Part I, Beginner Concepts

The book starts with articles about some of the corners of Perl that flummox beginners—and often experienced Perl programmers as well. You’ll find information here that many tutorials lack.

Part II, Regular Expressions

The articles in this section look under the hood of Perl’s regular expression engine, showing you how to create perfect patterns the first time you write them. If you don’t know why it’s important that Perl’s regex engine implements a nondeterministic finite automaton, you don’t know everything you should about Perl’s regular expressions.

Part III, Computer Science

In this section, Perl is used to demonstrate key computer science topics, ranging from practical implementations of complex data structures to information retrieval and pseudorandom number generation.

Part IV, Programming Techniques

Perl’s motto is There’s More Than One Way To Do It. This section shows you how to turn this flexibility to your advantage, demonstrating how to create your own data structures, change the behavior of Perl’s operators, extend Perl’s object-oriented mechanisms, and more.

Part V, Software Development

The articles in this section discuss systems and techniques for creating, testing, and debugging Perl programs.

Part VI, Networking

This section shows you why Perl has a reputation as a “glue” language, demon strating its use for creating client-server applications, sending mail, streaming audio, ferrying files around the Internet, and making Microsoft Office applications scriptable from your programs.

Part VII, Databases

Perl’s database support makes it possible for your Perl programs to stay the same no matter what database you’re using. You can migrate from MySQL to Oracle (or back!) seamlessly using the DBI module. This section covers the DBI, LDAP, ODBC, Access, Excel, and a customized web database created for the Human Genome Project.

Part VIII, Internals

This section dives into Perl’s guts, showing you how Perl works under the hood and explaining the components of the Perl distribution.

Be aware that this book has 41 different authors. The articles within each section are loosely ordered from general to specific, and also from simplest to most complex, but since these spectra are not one and the same, the progression is not always uniform. The book may be read straight through, or sampled at random. (In deference to the Perl motto, There’s More Than One Way To Read It.)

Normally, O’Reilly likes their books to be written by one author, or just a few. Books that are collections of many independently-written chapters may get to press more quickly, but discordant tones, styles, and levels of exposition can be jarring; worse, authors writing in parallel and under deadline rarely know what other contributors have covered, and therefore can’t provide the appropriate context to the reader.

That would indeed be a problem for this book had it been written in 2 months by 41 authors writing simultaneously. But in a sense, this book was written very carefully and methodically over six years. As editor, I had a difficult decision to make with every issue. TPJ was a grass-roots publication with no professional publishing experience behind it; I couldn’t afford to take out full color ads or launch huge direct-mail campaigns. So word of the magazine spread slowly, and instead of a steady circulation, it started tiny (400 subscribers for issue #1) and grew by several hundred each issue, peaking at 12,000 when EarthWeb began producing the magazine with issue #13.

Every issue, there were a lot of new subscribers, many of whom were new to Perl. Common sense dictated that I should include beginner articles in every issue, but I didn’t like where that line of reasoning led. If I catered to the novices in every issue, far too many articles would be about beginner topics, crowding out the advanced material. And I’d have to find a way to cover the important material over and over, imparting a fresh spin every time. Steve Lidie’s Perl/Tk column was a good example: it started with the basics and delved deeper with every article. Readers new to Perl/Tk who began with TPJ #15 didn’t need to know about the intricacies of Perl/Tk menus covered in that issue; they wanted to know how to create a basic Perl/Tk application—a topic covered way back in TPJ #1. But if I periodically “reset” topics and ran material already covered in past issues, I’d alienate long-time subscribers.

So I did something very unusual for a magazine: I made it easy (and cheap) for subscribers to get all of the back issues when they subscribed, so they’d be able to enjoy the introductory material. Unfortunately, that meant I had to keep reprinting back issues as I ran out. This is called a Supply Chain Management problem in the business world. (The solution: my basement.)

A side effect of this approach was that the articles hang together well: they tell a consistent “story” in a steady progression from TPJ #1 through TPJ #20, with little redundancy. TPJ was always a book—it just happened to be published in 20 quarterly installments.

There is another advantage to having a book with programs by 41 Perl experts: collectively, the articles constitute a good sampling of Perl “in the wild.” Every author has his own preferences—whether it’s use of the English pragma, prototyping subroutines, embracing or eschewing object-oriented programming, or any of the other myriad ways in which Perl’s expressivity is enjoyed. When you read a book by one author, you experience a single coherent (and hopefully good) style; when you read a book by dozens of experienced authors, you benefit from the diversity.

Naturally, there’s some TPJ material that doesn’t hold up well over time: modules become obsolete, features change, and news becomes history. Those articles didn’t make the cut; the rest are in this book and the two companion books, Web, Graphics and Perl/Tk: Best of The Perl Journal and Games, Diversions and Perl Culture: Best of The Perl Journal.

Enjoy!

Finding Perl Resources

Beginning with TPJ #10, I placed boxes at the top of most articles telling readers where they could find any resources mentioned in the article. Often, it ended up looking like this, because nearly everything in Perl is available on CPAN:

	Perl 5.004 or later..................CPAN

	Class::ISA...........................CPAN

	Memoize..............................CPAN

	Class::Multimethods..................CPAN

The CPAN (Comprehensive Perl Archive Network) is a worldwide distributed repository of Perl modules, scripts, documentation, and Perl itself. You can find the CPAN site nearest you at http://cpan.org, and you can search CPAN at http://search.cpan.org. To find, say, the Class::Multimethods module, you could search for “Multimethods” at http://search.cpan.org, or you could visit http://cpan.org and click on “Modules” and then “All Modules.” Either way, you’ll find a link for a Class-Multimethods.tar.gz file (which will include a version number in the filename). Download, unpack, build, and install the module as I describe in http://cpan.org/modules/INSTALL.html.

For information and code that isn’t available on CPAN, there are Reference sections at the ends of articles.

Conventions Used in This Book

The following conventions are used in this book:

Italic

Used for filenames, directory names, URLs, emphasis, and for the first use of a technical term.

Constant width

Used for code, command output, program names, and email addresses.

Constant width bold

Used for user input and code emphasis.

Constant width italic

Used for code placeholders, e.g., open(ARGUMENTS).

Comments and Questions

Please address comments and questions concerning this book to the publisher:

O’Reilly & Associates, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international/local)
(707) 829-0104 (fax)

There is a web page for this book containing all of the major code listings as well as any auxiliary files, errata, or additional information. You can access this page at:

http://www.oreilly.com/catalog/tpj1

To comment or ask technical questions about this book, send email to:

For information about books, conferences, Resource Centers, and the O’Reilly Network, see the O’Reilly web site at:

http://www.oreilly.com

Acknowledgments

First, an obvious thanks to the 120 TPJ contributors, and a special shout-out to the most prolific: Lincoln D. Stein, Mark Jason Dominus, Felix Gallo, Steve Lidie, Chris Nandor, Nathan Torkington, Sean M. Burke, and Jeffrey Friedl.

Next up are the people who helped with particular aspects of TPJ production. TPJ was mostly a one-man show, but I couldn’t have done it without the help of Nathan Torkington, Alan Blount, David Blank-Edelman, Lisa Traffie, Ellen Klempner-Beguin, Mike Stok, Sara Ontiveros, and Eri Izawa.

Sitting in the third row are people whose actions at particular junctures in TPJ’s existence helpedin crease the quality of the magazine and further its reach: Tim O’Reilly, Linda Walsh, Mark Brokering, Tom Christiansen, Jeff Dearth, the staff of Quantum Books in Cambridge, Lisa Sloan, Neil Bauman, Monica Lee, Cammie Hufnagel, and Sandy Aronson. Best wishes to the folks at CMP: Amber Ankerholz, Edwin Rothrock, Jon Erickson, and Peter Westerman.

Next, the folks at O’Reilly who helped this book happen: Hanna Dyer, Paula Ferguson, David Futato, Colleen Gorman, Sarmonica Jones, Linda Mui, Erik Ray, Mike Sierra, Betsy Waliszewski, Johnna VanHoose Dinse, Ellie Volckhausen, Neil Walls, Sue Willing, and the late Frank Willison.

People who helped out in small but crucial ways: David H. Adler, Tim Allwine, Elaine Ashton, Sheryl Avruch, Walter Bender, Pascal Chesnais, Damian Conway, Eamon Daly, Liza Daly, Chris DiBona, Diego Garcia, Carolyn Grantham, Jarkko Hietaniemi, Doug Koen, Uri Guttman, Dick Hardt, Phil Hughes, Mark Jacobsen, Lorrie LeJeune, Kevin Lenzo, LUCA, Tuomas J. Lukka, Paul Lussier, John Macdonald, Kate McDonnell, Chris Metcalfe, Andy Oram, Curtis Pew, Madeline Schnapp, Alex Shah, Adam Turoff, Sunil Vemuri, and Larry Wall.

Finally, a very special thanks to my wife, Robin, and my parents, Jack and Carol.

Get Computer Science & Perl Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.