Mastering Perl

Book description

This is the third in O'Reilly's series of landmark Perl tutorials, which started with Learning Perl, the bestselling introduction that taught you the basics of Perl syntax, and Intermediate Perl, which taught you how to create re-usable Perl software. Mastering Perl pulls everything together to show you how to bend Perl to your will. It convey's Perl's special models and programming idioms.

This book isn't a collection of clever tricks, but a way of thinking about Perl programming so you can integrate the real-life problems of debugging, maintenance, configuration, and other tasks you encounter as a working programmer.

The book explains how to:

  • Use advanced regular expressions, including global matches, lookarounds, readable regexes, and regex debugging
  • Avoid common programing problems with secure programming techniques
  • Profile and benchmark Perl to find out where to focus your improvements
  • Wrangle Perl code to make it more presentable and readable
  • See how Perl keeps track of package variables and how you can use that for some powerful tricks
  • Define subroutines on the fly and turn the tables on normal procedural programming.
  • Modify and jury rig modules to fix code without editing the original source
  • Let your users configure your programs without touching the code
  • Learn how you can detect errors Perl doesn't report, and how to tell users about them
  • Let your Perl program talk back to you by using Log4perl
  • Store data for later use in another program, a later run of the same program, or to send them over a network
  • Write programs as modules to get the benefit of Perl's distribution and testing tools
Appendices include "brian's Guide to Solving Any Perl Problem" to improve your troubleshooting skills, as well as suggested reading to continue your Perl education. Mastering Perl starts you on your path to becoming the person with the answers, and, failing that, the person who knows how to find the answers or discover the problem.

Publisher resources

View/Submit Errata

Table of contents

  1. Mastering Perl
  2. A Note Regarding Supplemental Files
  3. Foreword
  4. Preface
    1. Structure of This Book
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Enabled
    5. Comments and Questions
    6. Acknowledgments
  5. 1. Introduction: Becoming a Master
    1. What It Means to Be a Master
    2. Who Should Read This Book
    3. How to Read This Book
    4. What Should You Know Already?
    5. What I Cover
    6. What I Don’t Cover
  6. 2. Advanced Regular Expressions
    1. References to Regular Expressions
      1. (?imsx-imsx:PATTERN)
      2. References As Arguments
    2. Noncapturing Grouping, (?:PATTERN)
    3. Readable Regexes, /x and (?#...)
    4. Global Matching
      1. Global Match Anchors
    5. Lookarounds
      1. Lookahead Assertions, (?=PATTERN) and (?!PATTERN)
        1. Positive lookahead assertions
        2. Negative lookahead assertions
      2. Lookbehind Assertions, (?<!PATTERN) and (?<=PATTERN)
    6. Deciphering Regular Expressions
    7. Final Thoughts
    8. Summary
    9. Further Reading
  7. 3. Secure Programming Techniques
    1. Bad Data Can Ruin Your Day
    2. Taint Checking
      1. Warnings Instead of Fatal Errors
      2. Automatic Taint Mode
      3. mod_perl
      4. Tainted Data
      5. Side Effects of Taint Checking
    3. Untainting Data
      1. IO::Handle::untaint
      2. Hash Keys
      3. Choosing Untainted Data with Tainted Data
    4. List Forms of system and exec
      1. Three-Argument open
      2. sysopen
      3. Limit Special Privileges
    5. Summary
    6. Further Reading
  8. 4. Debugging Perl
    1. Before You Waste Too Much Time
    2. The Best Debugger in the World
      1. Doing Whatever I Want
      2. Program Tracing
      3. Safely Changing Modules
      4. Wrapping Subroutines
    3. perl5db.pl
    4. Alternative Debuggers
      1. Using a Different Debugger with -D
      2. Devel::ptkdb
      3. Devel::ebug
    5. Other Debuggers
      1. EPIC
      2. Komodo
      3. Affrus
    6. Summary
    7. Further Reading
  9. 5. Profiling Perl
    1. Finding the Culprit
    2. The General Approach
    3. Profiling DBI
      1. Other DBI::Profile Reports
      2. Making It Even Easier
      3. Switching Databases
    4. Devel::DProf
    5. Writing My Own Profiler
      1. Devel::LineCounter
    6. Profiling Test Suites
      1. Devel::Cover
    7. Summary
    8. Further Reading
  10. 6. Benchmarking Perl
    1. Benchmarking Theory
    2. Benchmarking Time
    3. Comparing Code
    4. Don’t Turn Off Your Thinking Cap
    5. Memory Use
    6. The perlbench Tool
    7. Summary
    8. Further Reading
  11. 7. Cleaning Up Perl
    1. Good Style
    2. perltidy
    3. De-Obfuscation
      1. De-Encoding Hidden Source
      2. Unparsing Code with B::Deparse
    4. Perl::Critic
      1. Creating My Own Perl::Critic Policy
    5. Summary
    6. Further Reading
  12. 8. Symbol Tables and Typeglobs
    1. Package and Lexical Variables
      1. Getting the Package Version
    2. The Symbol Table
      1. Typeglobs
      2. Aliasing
      3. Filehandle Arguments in Older Code
      4. Naming Anonymous Subroutines
    3. Summary
    4. Further Reading
  13. 9. Dynamic Subroutines
    1. Subroutines As Data
    2. Creating and Replacing Named Subroutines
    3. Symbolic References
    4. Iterating Through Subroutine Lists
    5. Processing Pipelines
    6. Method Lists
    7. Subroutines As Arguments
    8. Autoloaded Methods
    9. Hashes As Objects
    10. AutoSplit
    11. Summary
    12. Further Reading
  14. 10. Modifying and Jury-Rigging Modules
    1. Choosing the Right Solution
      1. Sending Patches to the Author
      2. Local Patches
      3. Taking over a Module
      4. Forking
      5. Start Over on My Own
    2. Replacing Module Parts
    3. Subclassing
      1. An ExtUtils::MakeMaker Example
      2. Other Examples
    4. Wrapping Subroutines
    5. Summary
    6. Further Reading
  15. 11. Configuring Perl Programs
    1. Things Not to Do
      1. Code in a Separate File
    2. Better Ways
      1. Environment Variables
      2. Special Environment Variables
      3. Turning on Extra Output
    3. Command-Line Switches
      1. The -s Switch
      2. Getopt Modules
        1. Getopt::Std
        2. Getopt::Long
    4. Configuration Files
      1. ConfigReader::Simple
      2. Config::IniFiles
      3. Config::Scoped
      4. AppConfig
      5. Other Configuration Formats
    5. Scripts with a Different Name
    6. Interactive and Noninteractive Programs
    7. perl’s Config
      1. Different Operating Systems
    8. Summary
    9. Further Reading
  16. 12. Detecting and Reporting Errors
    1. Perl Error Basics
      1. Operating System Errors
      2. Child Process Errors
      3. Errors Specific to the Operating System
    2. Reporting Module Errors
      1. Separation of Concerns
    3. Exceptions
      1. eval
      2. Multiple Levels of die
      3. die with a Reference
      4. Propagating Objects with die
      5. Fatal
    4. Summary
    5. Further Reading
  17. 13. Logging
    1. Recording Errors and Other Information
    2. Log4perl
      1. Configuring Log4perl
      2. Persistent Logging
      3. Other Log::Log4perl Features
    3. Summary
    4. Further Reading
  18. 14. Data Persistence
    1. Flat Files
      1. pack
      2. Data::Dumper
      3. Similar Modules
      4. YAML
    2. Storable
      1. Freezing Data
    3. DBM Files
      1. dbmopen
      2. DBM::Deep
    4. Summary
    5. Further Reading
  19. 15. Working with Pod
    1. The Pod Format
      1. Directives
      2. Body Elements
      3. Multiline Comments
    2. Translating Pod
      1. Pod Translators
      2. Pod::Perldoc::ToToc
      3. Pod::Simple
      4. Subclassing Pod::Simple
      5. Pod in Your Web Server
    3. Testing Pod
      1. Checking Pod
      2. Pod Coverage
      3. Hiding and Ignoring Functions
    4. Summary
    5. Further Reading
  20. 16. Working with Bits
    1. Binary Numbers
      1. Writing in Binary
    2. Bit Operators
      1. Unary NOT, ~
      2. Bitwise AND, &
      3. Binary OR, |
      4. Exclusive OR, ^
      5. Left << and right >> shift operators
    3. Bit Vectors
    4. The vec Function
      1. Bit String Storage
      2. Storing DNA
    5. Keeping Track of Things
    6. Summary
    7. Further Reading
  21. 17. The Magic of Tied Variables
    1. They Look Like Normal Variables
    2. At the User Level
    3. Behind the Curtain
    4. Scalars
      1. Tie::Cycle
      2. Bounded Integers
      3. Self-Destructing Values
    5. Arrays
      1. Reinventing Arrays
      2. Something a Bit More Realistic
    6. Hashes
    7. Filehandles
    8. Summary
    9. Further Reading
  22. 18. Modules As Programs
    1. The main Thing
    2. Backing Up
    3. Who’s Calling?
    4. Testing the Program
      1. Creating the Program Distribution
      2. Adding to the Script
    5. Distributing the Programs
    6. Summary
    7. Further Reading
  23. A. Further Reading
    1. Perl Books
    2. Non-Perl Books
  24. B. brian’s Guide to Solving Any Perl Problem
    1. My Philosophy of Problem-Solving
    2. My Method
  25. Index
  26. About the Author
  27. Colophon
  28. Copyright

Product information

  • Title: Mastering Perl
  • Author(s): brian d foy
  • Release date: July 2007
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596527242