It's a collection of 101 tricks for Perl developers from programming masters. To improve your daily life, your programming skills or your "Perl fu".
Perl Hacks starts with a presentation of authors (there is 3 main ones + plenty of well known Perl community members). It is really nice and make me think of the recent Highlighting members of the Perl family from Mark Gardner 😀
The book is not for beginners. It is old and some hacks are outdated because of this. And finally some hacks are just not interesting but this is really a tiny portion of the 101 hacks.
It starts smooth with less known perldoc arguments (do you know that you can "search" the perldoc with
Ever heard about Pod::Webserver?
There are hacks for enlightened users of vim or emacs like testing syntax on file saving, fix indent, run tests...
The next tricks are real life problems (make interactive programs silent when not interactive) or use
prompt for better prompts (lists, hierarchical menus...)! It's expanded later into the usage of ExtUtils::MakeMaker (when a module needs to ask user for informations).
And finally a nice HTTP::Proxy trick.
"A little subtlety, style and finesse and you can write easy-to-understand code that's just as powerful as the wild-eyed forge-ahead-at-all-costs just-do-the-job code."
Slurping and tying CSV files into Perl arrays, spreadsheets portability or reading file backwards (simple but not simple).
I discovered SQL::Library which is interesting concept (does a language portable version of this exists?).
Of course SQL statements bindings are introduced (hello little Bobby 👋) with the
NAME_lc trick (read the book to know what it is 😜).
It ends with iterator and
Aliasing package names, PERL5LIB,
use lib, configure, sitecustomize, reload modules, modules bundles, trace modules (code reference in
@INC)... So much fun!
This is EXACTLY for these kind of "hacks" that I was eager to read this book (I think some of these hacks have leaked and I fall on these somewhere :D).
Monkey Patching external modules is a morally questionable hack but still interesting. I learned that
die is often better than
die can be caught.
The hack "Drink to the CPAN" is... original... to say the less 😁
Hacks about packaging with PAR.
One hack is more "social": a complete walk-through about how to be a good open source bug reporter.
Hacks about Oriented Object Programming like attributes, true private methods dealing with typeglob (this hack is totally mad!), auto declare arguments or auto generate accessor, access control, polymorphism.
I think I leaned somewhere in this chapter the
$" = "][" trick which I found very cool.
Some debugging hacks from basic ones (
perl -c or bracketing your variables in your printf debugging sessions) to more intermediate things like using tests cases or Smart::Comments (great!) or extend stacktrace on error (or deparse/name anonymous subs) or even customize the debugger.
This sections provides hacks at module level (segregate tests, helper script to rebuild a module, run tests automatically or print test failures in color).
Beware of the fact that studying ExtUtils::MakeMaker source code will make you "wake up fully clothed and shivering in the shower several hours later".
In previous chapter, closure were introduced, now it's time for the another cool programming feature memoize! (and Ackerman function).
Some other hacks concern building Perl from source and using a file watcher to constantly run tests 👍
It starts with PHASES (you know BEGIN/END/CHECK...) then continue with dump,
corelist and tracing core modules (survival must have hacks).
This is probably the most "sysadmin" chapter:
"For sysadmin, stability is a way of life, not a goal" and "We are in the golden age of Perl testing".
An interesting (but I bet outdated) hack introduces PersistentPerl.
Actually more you advance in the book and the less there is to trash, 30 last hacks are just all competing being more mad than each others!
Write your own warnings....
Play with soft and hard refs...
Lock hash keys (prevent autovivication)...
Replacing CORE sub...
Contextual return value...
List comprehension in Perl...
Add your own Perl syntax... ("Although Perl is not perfect, it is Perfectable")
Use shared library...
Calculation with intervals...
Operator overload... 😵 ("Perl is a operator-oriented language" -> behavior of datas depends on what ops you decide to perform on them)
It's sweet nectar. 😍
It ends with an advice on deobfuscation of JAPHs
If you read so far, it's clear that you're just another Perl hacker too! 🐫