DEV Community


Posted on

Book review "Perl Hacks"

Perl Hacks


Perl Hacks is not a book like you're used to read. It's not a tutorial or developing a topic like network programming. It's even not a selection of blog posts.

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".

I'm a big fan of Chromatic and its Modern Perl which I consider a masterpiece. I'm shy to have no review of it on this blog, one day maybe.

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.

Productivity Hacks

It starts smooth with less known perldoc arguments (do you know that you can "search" the perldoc with -q)

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...

User Interaction Hacks

It's fun how the first hack is exactly something that I coded myself in the past (Perl static site generator).
Mind blow

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).

It's great how each contributor came with its area of expertise... Like the SDL introduction by Guillaume Cottenceau. Yes... the guy behind Frozen-Bubble!

Frozen Bubble

And finally a nice HTTP::Proxy trick.

Data Munging Hacks

"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 wantarray.

Working With Modules Hacks

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 exit since 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.

Object Hacks

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.

Debugging Hacks

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.

Developer Tricks Hacks

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 👍

Know Thy Code Hacks

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".

Other hacks are about typeglobs (find them) or Backend compiler collection (B::Concise or B::TerseSize) or Devel::SymDump, very interesting!

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!


Trace ops...
Write your own warnings....
Play with soft and hard refs...
Lock hash keys (prevent autovivication)...
Replacing CORE sub...
Contextual return value...
Active values...
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! 🐫

Top comments (3)

bbrtj profile image

Okay you've got me. Now I need this book

amasonpol profile image
John • Edited

I prefer to read such books in electronic form. I find it hard to read non-fiction on paper. If I read a programming book electronically, I can easily copy some terms I don't know and learn its definition. Right now, I'm reading a book by Erich Maria Remarque, "Life Borrowed". I enjoy reading authors of a lost generation. Immediately I am reminded that the [ of reading books[/url] are about memory and changing our mentality and enriching our vocabulary. I added your book to my "want to read" list on the bookstore website. Thanks for the advice.

thibaultduponchelle profile image

Ahah for me it’s the contrary I prefer on paper

Some comments have been hidden by the post's author - find out more