Copyright © 2006 O'Reilly Media, Inc. All rights reserved.
Printed in the United States of America.
Published by O'Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O'Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or firstname.lastname@example.org.
Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc. The Hacks series designations, Perl Hacks, the image of a pair of work boots, and related trade dress are trademarks of O'Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
Small print: The technologies discussed in this publication, the limitations on these technologies that technology and content owners seek to impose, and the laws actually limiting the use of these technologies are constantly changing. Thus, some of the hacks described in this publication may not work, may cause unintended harm to systems on which they are used, or may not be consistent with applicable user agreements. Your use of these hacks is at your own risk, and O'Reilly Media, Inc. disclaims responsibility for any damage or expense resulting from their use. In any event, you should take care that your use of these hacks does not violate any applicable laws, including copyright laws.
About the Authors
chromatic works for O'Reilly Media, where he edits the free and open source web sites of the O'Reilly Network. In his spare time, he writes books such as this one. In the remaining minutes, he contributes to the CPAN, Perl 5, Perl 6, Parrot, and even Pugs. He lives just west of Portland, Oregon by a park and a creek and would like to finish more projects someday, including writing a novel, a comic book, a television show, and sleeping. Catch up on his hobbies at http://wgz.org/chromatic.
Dr. Damian Conway is a professional Perl boffin. As the author of numerous popular CPAN modules (http://search.cpan.org/~dconway) and two highly regarded books on Perl, he is also a widely sought-after conference speaker and runs an international IT training companyThoughtstream (http://damian.conway.org)which provides Perl training from beginner to masterclass level throughout Europe, North America, and Australasia. He spends most of his less-than-copious free time working with Larry Wall on the design of Perl 6. [Hack #5], [Hack #13], [Hack #14], [Hack #34], [Hack #54], [Hack #86], [Hack #90], [Hack #92], [Hack #93], [Hack #94], [Hack #95], [Hack #99], [Hack #100]
Earlier this century, displaying his usual stellar sense of timing, Curtis "Ovid" Poe switched from mainframes to web programming in Perl and promptly watched the dot-com industry implode. Despite this minor setback and working for several currently non-existent companies, Ovid stuck with Perl and actually discovered he liked it. A frequent speaker at user groups and author of numerous CPAN modules and a popular Perl CGI course, Ovid is a Perl Foundation Steering Committee member and also heads the TPF grant committee. [Hack #10], [Hack #31], [Hack #50], [Hack #56], [Hack #57], [Hack #58], [Hack #60]
About the Contributors
Perl is also a language with a rich and varied community of experts, wizards, gurus, goofs, and ne'er-do-wells. A few of the most colorful characters contributed to this book.
Adrian Howard still hopes that Lisp and Smalltalk will take over the world, but in the meantime gets paid for playing with Perl and Ruby amongst other things. Agile fanatic. Testing bigot. Usability zealot. Recently guilt tripped into being a Perl Grant Manager by Ovid. Saving up for a small castle to share with his beloved Kathryn and a small band of loyal Yorkshire Terriers. [Hack #15], [Hack #63]
Chris Dolan is a software developer living in Madison, Wisconsin. With a Ph.D. in Astronomy, he has a very strong math and science background. He started programming professionally as a teenager in the late 1980s. During his free time, he is an active participant in several online software development communities and is an avid bicyclist. [Hack #40]
David Landgren started using Perl 4.019 when awk was no longer sufficient to cope with the things he was trying to do. In 1999 he founded the Paris Perl Mongers and helped organize the YAPC::Europe 2003 conference. He currently works at a large French human resources firm, where he likes to go by the title of IT Operations Manager, using Perl everywhere. He spends what little spare time he has left writing summaries for the perl5-porters mailing list. Contact him at email@example.com. [Hack #98]
David Wheeler, a longtime Perl hacker, made a name for himself as the lead developer of the Bricolage content management system, and as President and founder of Kineticode (http://www.kineticode.com), a web software company. His work on Bricolage led him over the last year to develop the Kinetic Platform, a next-generation enterprise web services application platform. He lives in Portland, Oregon. [Hack #7], [Hack #28]
Guillaume Cottenceau is a software developer. He's been interested in computers for too long to remember, enjoys programming with various tools and languages, and found himself lucky enough to be the catalyst for a game written in Perl called "Frozen-Bubble" which is regularly cited as the favorite game of the Linux community. [Hack #16]
H. Merijn Brand is a Perl 5 porter, the Configure pumpking, and an Amsterdam Perl Monger. He was born on December 30, 1961, is married, and has two kids. He has worked as a data analyst for PROCURA B.V. in The Netherlands since June 1991. Visit his home page at http://mirrors.develooper.com/hpux. [Hack #21]
Jesse Vincent doesn't drink that often, but does find that a drink or two tends to improve the CPAN remarkably. [Hack #37]
Joe McMahon is a test automation architect at Yahoo! whose background includes extensive development experience: 25 years of work at NASA, with everything from spacecraft ground communications systems to Web development. He has contributed to core Perl test support, supplied the debuggers internal documentation, and supports several CPAN modules, from App::SimpleScan and WWW::Mechanize::Pluggable to Date::PeriodParser and GraphViz::Data::Structure. [Hack #59]
Joshua ben Jore came to Perl because he had to write a CGI app for a political campaign and he'd heard that Perl was best for that sort of thing. He stayed when he found out for himself how wonderful CPAN was. His latest projects have been working toward getting Lispy macros and lazy evaluation in Perl and learning what Prolog has to offer. He is well-known at perlmonks.org under the handle diotalevi and admits to being a Morris dancer. [Hack #83]
Michael Graham is a Perl programmer who lives in Toronto where he writes web applications with CGI::Application and its rich suite of plug-ins. He works at Wilder & Associates (http://www.wilder.ca). He likes music, long walks on the beach, and test-driven development. [Hack #68], [Hack #69]
Philippe "BooK" Bruhat, author of HTTP::Proxy and Net::Proxy, lives in Lyon, France with his wife and cat and is an active member of the French and European Perl communities. He worked on the translations of Programming Perl, 3rd Edition and Perl Best Practices for O'Reilly France, and publishes Perl articles in GNU/Linux Magazine France. As the co-developper of Act (A Conference Toolkit) and a member of the YAPC Europe Foundation, he helps organize European Perl workshops and conferences, at which he is also a regular speaker. He would love it if you tried his Acme::MetaSyntactic module (updated weekly). [Hack #18], [Hack #97]
Ricardo Signes trained for a career in philosophy, but the sudden onset of the Industrial Revolution forced him to work with baser forms of logic. He lives in Bethlehem, Pennsylvania and writes Perl for Pobox.com. [Hack #8]
Sean M. Burke is a perfectly normal human being, based on organic molecules, and exhibiting bilateral symmetry. He is typical. He has written two O'Reilly books, Perl and LWP and RTF Pocket Guide, has contributed dozens of modules to CPAN, and was a regular columnist for The Perl Journal for about five years. (His articles appear in the various O'Reilly Best of the Perl Journal books, notably the Games, Diversions & Perl Culture volume.) Trained as a linguist, he now lives on an island in southeast Alaska, where he develops tools for Native language preservation. Wild rumors place his web site at http://interglacial.com. [Hack #3], [Hack #6], [Hack #11]
Simon Wistow currently herds London.pmthe largest and most rowdy of all the Perl Monger groups. In his spare time he writes rather too many CPAN modules of dubious usefulness. [Hack #39]
Stephen B. Jenkins (a.k.a. Erudil) is the senior programmer/analyst at the Aerodynamics Laboratory of the Institute for Aerospace Research, National Research Council of Canada. He has written for Dr. Dobb's Journal, Linux Journal, The Perl Journal, the USENIX Association, the American Institute of Aeronautics and Astronautics, the Aerospace and Electronics Systems Society of the IEEE, and the Association for Computing Machinery. For more info, see http://www.Erudil.com. [Hack #101]
Tim Allwine is a Senior Software Engineer at O'Reilly Media, Inc. He develops software for the Market Research group, writes various spidering tools that collect data from disparate sites, and is involved in the development of web services at O'Reilly. [Hack #71]
Tom Moertel is a regular contributer to the Pittsburgh Perl Mongers. He created Test::LectroTest, a specification-based testing system for Perl, and PXSL ("pixel"), a convenient shorthand for writing markup-heavy XML documents. He also wrote The Coder's Guide to Coffee, a concise guide to the programmer's most misunderstood utility beverage. He lives in Pittsburgh, Pennsylvania, where he runs a consulting practice specializing in solving difficult software problems. Read more about his projects and interests, which include espresso and functional programming, at http://blog.moertel.com. [Hack #61]
Brett Warden, BSEE, specializes in Perl programming and embedded/telco systems. He lives in the Northwest U.S. with his wife and son. You can find a collection of odd projects at http://www.wgz.com/bwarden. His Perl Monks username is isotope. [Hack #42]
The authors wish to thank their editor, Allison Randal, for shepherding the process and smoothing out all of the non-writing details, as well as the production and marketing and business departments at O'Reilly Media for turning this book from plain text into the lovely printed form you hold in your hands.
Thanks also to Nathan Torkington for helping to start this process.
Thanks go primarily to my co-authors, two fine programmers it is my privilege to know as colleagues and friends, as well as to all of the contributors, without whom this book would be much shorter, much less interesting, and much less fun. Thanks also go to my friends, family, and commiserators, especially the U of P crew and Aleatha, Esther, Eva, Kate, Katie, Laura, and Mel. Thanks and respect go to my work and hobby colleagues, including all of the programmers who have invented and refined these tools which allow us to work and play.
Finally, I dedicate this book to my family, Brett, Danielle, Jacob, Jack, and Brad in the hope that I am a worthy brother, brother-in-law, uncle, and cat caretaker.
To chromatic, Allison, and Nat, for inviting me to help them build this wonderful new Perl jungle gym. To Larry Wall, who invented the extraordinary playground upon which it is constructed. And to my many, many friends throughout the worldwide Perl community, whose encouragement and support has allowed me to play here for the past decade.
Above all, to my beloved Linda, whose love, beauty, and grace illuminate every day of my life.
Curtis "Ovid" Poe
There's no way I could have participated in this without the Perl community having patiently answered so many of my silly questions when I started learning Perl years ago. They didn't just teach me Perl, they taught me how to be a programmer. Many thanks to chromatic and Allison for shrink-wrapping my monkey. I'll never forgive you. Mostly, though, I want to thank Sean and Lil, two people without whom the world would be a sadder place for me.
The authors extend tremendous thanks to the technical reviewers who found many errors, suggested many rephrasings, and argued over important formatting details to make this book clear, accurate, and interesting. They are Ann Barcomb, Daniel Bosold, Brad Bowman, Philippe "BooK" Bruhat, the #cgiapp IRC channel, Chris Dolan, Michael Graham, Garick Hamlin, Joshua ben Jore, Yves Orton, Ricardo Signes, and David Wheeler.