Cover image for Mastering Perl, 2nd Edition

Book description

Take the next step toward Perl mastery with advanced concepts that make coding easier, maintenance simpler, and execution faster. Mastering Perl isn’t a collection of clever tricks, but a way of thinking about Perl programming for solving debugging, configuration, and many other real-world problems you’ll encounter as a working programmer.

Table of Contents

  1. 1. Introduction
  2. 2. Advanced Regular Expressions
    1. Captures
      1. Relative backreferences
      2. Named captures
      3. Unknown number of captures
      4. (?imsx-imsx:PATTERN)
      5. 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
  3. 3. Secure Programming Techniques
    1. Bad Data 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. Taint::Util
      4. Choosing Untainted Data with Tainted Data
      5. Symbolic References
    4. Defensive Database Programming with DBI
    5. List Forms of system and exec
      1. Three Argument open
      2. sysopen
      3. Limit Special Privileges
    6. Safe Compartments
      1. Safe Limitations
    7. Summary
    8. Further Reading
  4. 4. Debugging Perl
  5. 5. Profiling Perl
  6. 6. Benchmarking Perl
  7. 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
  8. 8. Symbol Tables and Typeglobs
  9. 9. Dynamic Subroutines
  10. 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
  11. 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. 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
  12. 12. Detecting and Reporting Errors
    1. Carp
    2. Perl Error Basics
      1. Operating System Errors
      2. Child Process Errors
      3. Errors Specific to the Operating System
    3. Reporting Module Errors
      1. Separation of Concerns
    4. Exceptions
      1. eval
      2. Multiple Levels of die
      3. die with a Reference
      4. Propagating Objects with die
      5. Clobbering $@
      6. autodie
    5. Catching Exceptions
      1. Try::Tiny
      2. TryCatch
    6. Polymorphic Return Values
    7. Summary
    8. Further Reading
  13. 13. Logging
    1. Recording Errors and Other Information
    2. Log4perl
      1. Subroutine Arguments
      2. Configuring Log4perl
        1. Adding My Own Information
      3. Persistent Configuration
      4. Logging Categories
        1. Categories are hierarchical
      5. Other Log::Log4perl Features
    3. Summary
    4. Further Reading
  14. 14. Data Persistence
  15. 15. Working with Pod
    1. The Pod Format
      1. Directives
      2. Encoding
      3. Body Elements
    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
  16. 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
      3. Checking Primes
    5. Keeping Track of Things
    6. Summary
    7. Further Reading
  17. 17. The Magic of Tied Variables
  18. 18. Modules as Programs
  19. A. Further Reading
    1. Perl Books
    2. Non-Perl Books
  20. B. brian’s Guide to Solving Any Perl Problem
    1. My Philosophy of Problem-Solving
    2. My Method
    3. Some Stupid Things I’ve Done and Still Do
  21. Index
  22. About the Authors
  23. Colophon
  24. Copyright