Rough Cuts are manuscripts that are developed but not yet published, available through Safari. Rough Cuts provide you access to the very latest information on a given topic and offer you the opportunity to interact with the author to influence the final publication.
This is the Rough Cut version of the printed book.
The Classic Guide to Solving Real-World Problems with Perl—Now Fully Updated for Today’s Best Idioms!For years, experienced programmers have relied on Effective Perl Programming to discover better ways to solve problems with Perl. Now, in this long-awaited second edition, three renowned Perl programmers bring together today’s best idioms, techniques, and examples: everything you need to write more powerful, fluent, expressive, and succinct code with Perl.
Nearly twice the size of the first edition, Effective Perl Programming, Second Edition, offers everything from rules of thumb to avoid common pitfalls to the latest wisdom for using Perl modules. You won’t just learn the right ways to use Perl: You’ll learn why these approaches work so well.
New coverage in this edition includes
You’ll learn how to work with strings, numbers, lists, arrays, strictures, namespaces, regular expressions, subroutines, references, distributions, inline code, warnings, Perl::Tidy, data munging, Perl one-liners, and a whole lot more. Every technique is organized in the same Items format that helped make the first edition so convenient and popular.
Foreword xi
Preface xiii
Acknowledgments xvii
About the Authors xix
Introduction 1
Chapter 1: The Basics of Perl 9
Item 1. Find the documentation for Perl and its modules. 9
Item 2. Enable new Perl features when you need them. 12
Item 3. Enable strictures to promote better coding. 14
Item 4. Understand what sigils are telling you. 17
Item 5. Know your variable namespaces. 19
Item 6. Know the difference between string and numeric comparisons. 21
Item 7. Know which values are false and test them accordingly. 23
Item 8. Understand conversions between strings and numbers. 27
Item 9. Know the difference between lists and arrays. 31
Item 10. Don’t assign undef when you want an empty array. 34
Item 11. Avoid a slice when you want an element. 37
Item 12. Understand context and how it affects operations. 41
Item 13. Use arrays or hashes to group data. 45
Item 14. Handle big numbers with bignum. 47
Chapter 2: Idiomatic Perl 51
Item 15. Use $_ for elegance and brevity. 53
Item 16. Know Perl’s other default arguments. 56
Item 17. Know common shorthand and syntax quirks. 60
Item 18. Avoid excessive punctuation. 66
Item 19. Format lists for easy maintenance. 68
Item 20. Use foreach, map, and grep as appropriate. 70
Item 21. Know the different ways to quote strings. 73
Item 22. Learn the myriad ways of sorting. 77
Item 23. Make work easier with smart matching. 84
Item 24. Use given-when to make a switch statement. 86
Item 25. Use do {} to create inline subroutines. 90
Item 26. Use List::Util and List::MoreUtils for easy list manipulation. 92
Item 27. Use autodie to simplify error handling. 96
Chapter 3: Regular Expressions 99
Item 28. Know the precedence of regular expression operators. 99
Item 29. Use regular expression captures. 103
Item 30. Use more precise whitespace character classes. 110
Item 31. Use named captures to label matches. 114
Item 32. Use noncapturing parentheses when you need only grouping. 116
Item 33. Watch out for the match variables. 117
Item 34. Avoid greed when parsimony is best. 119
Item 35. Use zero-width assertions to match positions in a string. 121
Item 36. Avoid using regular expressions for simple string operations. 125
Item 37. Make regular expressions readable. 129
Item 38. Avoid unnecessary backtracking. 132
Item 39. Compile regexes only once. 137
Item 40. Pre-compile regular expressions. 138
Item 41. Benchmark your regular expressions. 139
Item 42. Don’t reinvent