Preface

This is the third 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 contains 47 articles about the leisure pursuits of Perl programmers. You won’t find articles on web development or object-oriented programming here. This book is for relaxing and reveling in Perl culture—a mindset favoring programs that are weird, wacky, and hubristic.

This book is divided into seven sections:

Part I

This section contains six articles on the Perl culture, including an article by Larry Wall comparing computer languages to music, a “coffee-table” collection of the TPJ covers, an article on Perl style, two articles on home automation, and an analysis of the usefulness of the Usenet newsgroup comp.lang.perl.misc.

Part II

Many scientists gravitate toward Perl when they find that they can analyze their data more easily with Perl than other languages. In this section, you’ll find articles on astronomy, genetic algorithms, bioinformatics, and scientific computing.

Part III

Perl was created by a linguist, and it shows; there is no better language for manipulating text, whether it’s a simple task involving punctuation or full-fledged natural language processing. In this largest section of the book, 15 articles demonstrate a plethora of language-related tasks, from speech synthesis to “bots” that answer English queries to correcting typos and adapting your Perl programs for other languages.

Part IV

Most of this book is about leisurely pursuits, especially if your notion of leisure includes writing bots that converse well enough to be hit on. If it doesn’t, this section has more traditional games, from an overview of all the games available on CPAN to a solitaire game. It has all of the Perl quiz shows as well, to help you test and increase your Perl knowledge.

Part V

Perl Poetry has been around since 1990, and has been published in the Economist and the Guardian. In addition to the Perl Poetry contest, this section includes an article on reporting error messages in verse and how to search for rhymes in Perl.

Part VI

This section has three articles on how Perl can help maintain a stable democracy: two on voting methods, and one on how to prevent nuclear accidents.

Part VII

Perl’s flexibility lets you make your code look like readable computer programs, poetry, or modem line noise. TPJ began the Obfuscated Perl Contest, and in this section you’ll find the winning entries from all five contests as well as a complete collection of the one-liners that I used to fill up excess space in the magazine.

Be aware that this book has 31 different authors. Each section, and the articles within them, are loosely ordered from general to specific, and also from most accessible to least. Since these spectra are not identical, it’s not a strict progression. 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 are jarring to the reader; worse, authors writing in parallel and under deadline rarely know what other contributors have covered, and therefore can’t provide appropriate context.

That would indeed be a problem for this book had it been written in two months by 31 authors writing simultaneously. But in a sense, this book was written very carefully and methodically over six years.

Here’s why. As editor of The Perl Journal, 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 until EarthWeb began producing the magazine with issue #13.

For every issue there were 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—covered way back in TPJ #1. But if I periodically “reset” topics and ran material already covered in past issues, I might alienate long-time subscribers.

So I did something very unusual for a magazine: I made it easy (and cheap) for subscribers to get every single back issue when they subscribed, so they’d always have the introductory material. This meant that I had to keep reprinting back issues as I ran out. This is what business calls a Supply Chain Management problem. The solution: my basement.

A side-effect of this approach was that the articles hold well together: they tell a consistent “story” in a steady progression from TPJ #1 through TPJ #20, with little redundancy between them. 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 31 flavors of Perl expert: collectively, they constitute a good sampling of Perl “in the wild.” Every author has his own preferences—whether it’s use of the English pragma, prototyping their 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. It’s an Olympic-size meme pool.

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, Computer Science & Perl Programming: Best of The Perl Journal and Web, Graphics, and Perl/Tk: 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.8 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 can either search for “Multimethods” at http://search.cpan.org, or you can 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 some 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, functions, and email addresses.

Constant width bold

Used for user input and code emphasis.

Constant width italic

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

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: Games, Diversions & Perl Culture by Jon Orwant (O’Reilly). Copyright 2003 Readable Publications, Inc., ISBN 978-0-5960-0312-8.

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at permissions@oreilly.com.

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, which lists errata, examples, or any additional information. You can access this page at:

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

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 contributors for the three books in this series, 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. Sean’s articles, in particular, are well-represented in this book.

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 helped increase 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, Sarmonica Jones, Linda Mui, Erik Ray, Betsy Waliszewski, Jane Ellin, Judy Hoer, Ellie Volckhausen, Sue Willing, and the late great 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 Games, Diversions & Perl Culture 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.