Advanced Perl Programming, 2nd Perl Programming. 2nd Edition.pdf Perl changed in other ways, too:...

Click here to load reader

  • date post

  • Category


  • view

  • download


Embed Size (px)

Transcript of Advanced Perl Programming, 2nd Perl Programming. 2nd Edition.pdf Perl changed in other ways, too:...

  • Advanced Perl Programming, 2nd Edition By Simon Cozens ............................................... Publisher: O'Reilly Pub Date: June 2005 ISBN: 0-596-00456-7 Pages: 304

    Table of Contents | Index

    With a worldwide community of users and more than a million dedicated programmers, Perl has proven to be the most effective language for the latest trends in computing and business.

    Every programmer must keep up with the latest tools and techniques. This updated version of Advanced Perl Programming from O'Reilly gives you the essential knowledge of the modern Perl programmer. Whatever your current level of Perl expertise, this book will help you push your skills to the next level and become a more accomplished programmer.

    O'Reilly's most high-level Perl tutorial to date, Advanced Perl Programming, Second Edition teaches you all the complex techniques for production-ready Perl programs. This completely updated guide clearly explains concepts such as introspection, overriding built- ins, extending Perl's object-oriented model, and testing your code for greater stability.

    Other topics include:

    Complex data structures


    Templating toolkits

    Working with natural language data


    Interaction with C and other languages

    In addition, this guide demystifies once complex topics like object-relational mapping and event-based development-arming you with everything you need to completely upgrade your skills.

    Praise for the Second Edition:

  • "Sometimes the biggest hurdle to problem solving isn't the subject itself but rather the sheer number of modules Perl provides. Advanced Perl Programming walks you through Perl's TMTOWTDI ("There's More Than One Way To Do It") forest, explaining and comparing the best modules for each task so you can intelligently apply them in a variety of situations." --Rocco Caputo, lead developer of POE

    "It has been said that sufficiently advanced Perl code is indistinguishable from magic. This book of spells goes a long way to unlocking those secrets. It has the power to transform the most humble programmer into a Perl wizard." --Andy Wardley

    "The information here isn't theoretical. It presents tools and techniques for solving real problems cleanly and elegantly." --Curtis 'Ovid' Poe

    " Advanced Perl Programming collects hard-earned knowledge from some of the best programmers in the Perl community, and explains it in a way that even novices can apply immediately." --chromatic, Editor of

  • Advanced Perl Programming, 2nd Edition By Simon Cozens ............................................... Publisher: O'Reilly Pub Date: June 2005 ISBN: 0-596-00456-7 Pages: 304

    Table of Contents | Index

    Copyright Preface Audience Contents Conventions Used in This Book Using Code Examples We'd Like to Hear from You Safari® Enabled Acknowledgments Chapter 1. Advanced Techniques Section 1.1. Introspection Section 1.2. Messing with the Class Model Section 1.3. Unexpected Code Section 1.4. Conclusion Chapter 2. Parsing Techniques Section 2.1. Parse::RecDescent Grammars Section 2.2. Parse::Yapp Section 2.3. Other Parsing Techniques Section 2.4. Conclusion Chapter 3. Templating Tools Section 3.1. Formats and Text::Autoformat Section 3.2. Text::Template Section 3.3. HTML::Template Section 3.4. HTML::Mason Section 3.5. Template Toolkit

  • Section 3.6. AxKit Section 3.7. Conclusion Chapter 4. Objects, Databases, and Applications Section 4.1. Beyond Flat Files Section 4.2. Object Serialization Section 4.3. Object Databases Section 4.4. Database Abstraction Section 4.5. Practical Uses in Web Applications Section 4.6. Conclusion Chapter 5. Natural Language Tools Section 5.1. Perl and Natural Languages Section 5.2. Handling English Text Section 5.3. Modules for Parsing English Section 5.4. Categorization and Extraction Section 5.5. Conclusion Chapter 6. Perl and Unicode Section 6.1. Terminology Section 6.2. What Is Unicode? Section 6.3. Unicode Transformation Formats Section 6.4. Handling UTF-8 Data Section 6.5. Encode Section 6.6. Unicode for XS Authors Section 6.7. Conclusion Chapter 7. POE Section 7.1. Programming in an Event-Driven Environment Section 7.2. Top-Level Pieces: Components Section 7.3. Conclusion Chapter 8. Testing Section 8.1. Test::Simple Section 8.2. Test::More Section 8.3. Test::Harness Section 8.4. Test::Builder Section 8.5. Test::Builder::Tester Section 8.6. Keeping Tests and Code Together Section 8.7. Unit Tests Section 8.8. Conclusion Chapter 9. Inline Extensions Section 9.1. Simple Inline::C Section 9.2. More Complex Tasks with Inline::C

  • Section 9.3. Inline:: Everything Else Section 9.4. Conclusion Chapter 10. Fun with Perl Section 10.1. Obfuscation Section 10.2. Just Another Perl Hacker Section 10.3. Perl Golf Section 10.4. Perl Poetry Section 10.5. Acme::* Section 10.6. Conclusion Colophon About the Author Colophon Index

  • Advanced Perl Programming, Second Edition

    by Simon Cozens

    Copyright © 2005, 1997 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 ( For more information, contact our corporate/institutional sales department: (800) 998-9938 or

    Editor: Allison Randal

    Production Editor: Darren Kelly

    Cover Designer: Edie Freedman

    Interior Designer: David Futato

    Production Services: nSight,Inc.

    Printing History:

    August 1997: First Edition.

    June 2005: Second Edition.

    Nutshell Handbook, the Nutshell Handbook logo, and the

  • O'Reilly logo are registered trademarks of O'Reilly Media, Inc. Advanced Perl Programming, the image of a of a black leopard, 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 author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.

    ISBN: 0-596-00456-7


  • Preface It was all Nathan Torkington's fault. Our Antipodean programmer, editor, and O'Reilly conference supremo friend asked me to update the original Advanced Perl Programming way back in 2002.

    The Perl world had changed drastically in the five years since the publication of the first edition, and it continues to change. Particularly, we've seen a shift away from techniques and toward resourcesfrom doing things yourself with Perl to using what other people have done with Perl. In essence, advanced Perl programming has become more a matter of knowing where to find what you need on the CPAN,[*] rather than a matter of knowing what to do.

    [*] The Comprehensive Perl Archive Network ( is the primary resource for user-contributed Perl code.

    Perl changed in other ways, too: the announcement of Perl 6 in 2000 ironically caused a renewed interest in Perl 5, with people stretching Perl in new and interesting directions to implement some of the ideas and blue-skies thinking about Perl 6. Contrary to what we all thought back then, far from killing off Perl 5, Perl 6's development has made it stronger and ensured it will be around longer.

    So it was in this context that it made sense to update Advanced Perl Programming to reflect the changes in Perl and in the CPAN. We also wanted the new edition to be more in the spirit of Perlto focus on how to achieve practical tasks with a minimum of fuss. This is why we put together chapters on parsing techniques, on dealing with natural language documents, on testing your code, and so on.

    But this book is just a beginning; however tempting it was to

  • try to get down everything I ever wanted to say about Perl, it just wasn't possible. First, because Perl usage covers such a wide spreadon the CPAN, there are ready-made modules for folding DNA sequences, paying bills online, checking the weather, and playing poker. And more are being added every day, faster than any author can keep up. Second, as we've mentioned, because Perl is changing. I don't know what the next big advance in Perl will be; I can only take you through some of the more important techniques and resources available at the moment.

    Hopefully, though, at the end of this book you'll have a good idea of how to use what's available, how you can save yourself time and effort by using Perl and the Perl resources available to get your job done, and how you can be ready to use and integrate whatever developments come down the line.