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.
Chapter 1 Introduction: Becoming a Master
What It Means to Be a Master
Who Should Read This Book
How to Read This Book
What Should You Know Already?
What I Cover
What I Don’t Cover
Chapter 2 Advanced Regular Expressions
References to Regular Expressions
Noncapturing Grouping, (?:PATTERN)
Readable Regexes, /x and (?#...)
Deciphering Regular Expressions
Chapter 3 Secure Programming Techniques
Bad Data Can Ruin Your Day
List Forms of system and exec
Chapter 4 Debugging Perl
Before You Waste Too Much Time
The Best Debugger in the World
Chapter 5 Profiling Perl
Finding the Culprit
The General Approach
Writing My Own Profiler
Profiling Test Suites
Chapter 6 Benchmarking Perl
Don’t Turn Off Your Thinking Cap
The perlbench Tool
Chapter 7 Cleaning Up Perl
Chapter 8 Symbol Tables and Typeglobs
Package and Lexical Variables
The Symbol Table
Chapter 9 Dynamic Subroutines
Subroutines As Data
Creating and Replacing Named Subroutines
Iterating Through Subroutine Lists
Subroutines As Arguments
Hashes As Objects
Chapter 10 Modifying and Jury-Rigging Modules
Choosing the Right Solution
Replacing Module Parts
Chapter 11 Configuring Perl Programs
Things Not to Do
Scripts with a Different Name
Interactive and Noninteractive Programs
Chapter 12 Detecting and Reporting Errors
Perl Error Basics
Reporting Module Errors
Chapter 13 Logging
Recording Errors and Other Information
Chapter 14 Data Persistence
Chapter 15 Working with Pod
The Pod Format
Chapter 16 Working with Bits
The vec Function
Keeping Track of Things
Chapter 17 The Magic of Tied Variables
They Look Like Normal Variables
At the User Level
Behind the Curtain
Chapter 18 Modules As Programs
The main Thing
Testing the Program
Distributing the Programs
Appendix Further Reading
Appendix brian’s Guide to Solving Any Perl Problem
brian d foy is a prolific Perl trainer and writer, and runs The Perl Review to help people use and understand Perl through educational, consulting, code review, and more. He's a frequent speaker at Perl conferences. He's the co-author of Learning Perl and Intermediate Perl and the author of Mastering Perl. He was been an instructor and author for Stonehenge Consulting Services from 1998 to 2009, a Perl user since he was a physics graduate student, and a die-hard Mac user since he first owned a computer. He founded the first Perl user group, the New York Perl Mongers, as well as the Perl advocacy nonprofit Perl Mongers, Inc., which helped form more than 200 Perl user groups across the globe. He maintains the perlfaq portions of the core Perl documentation, several modules on CPAN, and some stand-alone scripts.
Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects.
The animals on the cover of Mastering Perl are a vicuña (Vicugna vicugna) mother and her young. Vicuñas are found in the central Andes Mountains of South America, at altitudes of 4,000 to 5,500 meters. For centuries, the vicuña has been treasured for its coat of soft, insulating hair that produces some of the finest and rarest wool on Earth. Vicuña yarns and fabrics can fetch up to $3,000 per yard.
Vicuñas held a special place among ancient Incan societies. Incans believed that the animal was the reincarnation of a beautiful maiden who had received a coat of gold as a reward for succumbing to the advances of a decrepit and homely king. Every four years, Incans would hold a chacu, a hunt to trap thousands of vicuñas, shear their coats, and release them back to the wild. Incan law forbade the killing of vicuñas, and only members of royalty were allowed to wear garments made from the animal's coat.
Unregulated hunting of vicuñas led to the animal being placed on the endangered species list in 1974. By that time, their number had dwindled to 6,000. However, close regulation, particularly by the government of Peru, has led to the vicuña's resurgence, and today the number is over 120,000. The chacu is now sanctioned and regulated by the Peruvian government, and a portion of the profits is returned to villagers in the Andes.
The cover image is a 19th-century engraving from the Dover Pictorial Archive. The cover font is Adobe ITC Garamond. The text font is Linotype Birka; the heading font is Adobe Myriad Condensed; and the code font is LucasFont's TheSans Mono Condensed.
The journey to mastering Perl requires at least three (3) steps :)
One optional route would be to read:
1) Learning Perl
2) Intermediate Perl, and finally
3) Mastering Perl
brian d foy mentions in his introduction and appendix A that the path to mastery involves learning from many people, and to learn from brian is an advantage. Appendix A is a list of Further Reading and by following up on many of these compounds the effect of the book. You get the bang for your buck.
Chapter 3 on Secure Programming Techniques is helpful because it places the topic front and center. This topic should find its way downstream into Learning Perl to encourage secure programming as early as possible.
I found immediate value in the chapters on benchmarking, profiling (especially DBI profiling) and logging. The chapters on Cleaning Up Perl (chapter 7: perltidy and de-obfuscation) and Configuring Perl (chapter 11: dealing with switches) are a great recap of material critical for "creating professional programs with Perl".
PS _ My personal route to mastering Perl had a required stop at "Programming the Perl DBI".