This blog is also available on Gemini (What's Gemini?)

Review: Perl One-Liners


*Full Disclosure: I received a free review copy of this book*

I'm primarily a backend web programmer. I try to write in an object-oriented way with test-driven development practices, with each object having a well-defined purpose. I do this primarily in Perl, a language that causes many developers to get a twitch. The reason is that Perl has an old reputation as being messy line noise. Part of the reason for that reputation is because of the one-liner obfuscation games that used to be quite popular.

So when I first heard of this book, I was naturally inclined to avoid it. In a way, it's perpetuating an aspect of Perl that's best left as part of history. Besides, as a web developer, what did this book have to offer me?

What I found was that one-liners offer a different perspective, and it's a useful perspective to have. Converting a text document to double-spaced lines isn't a problem I have every day, but maybe I will at some point. When that or one of the many other problems this book addresses comes up, I'll have something within easy reach.

Perhaps more importantly than any specific problem is the attitude that programming in this fashion doesn't have to be inscrutable. Every one-liner here comes with a detailed explanation, and many come with alternative solutions with their own explanations. If we can document our concise solution in less space than a more "well-developed" solution would take, what's the problem?

Donald Knuth had attempted a system called "Literate Programming", where documentation and code are carefully interleaved. Jon Bentley, writer of the *Programming Pearls* column in *Communications of the ACM*, challenged Knuth to write a Literate Program for the following problem: read a file of text, determine the n most frequently used words, and print out a sorted list of those words along with their frequencies.

Knuth wrote a 10-page program. Bentley then turned around and wrote a 6-command shell pipeline to do the same thing, which also happened to miss a few bugs that Knuth had stumbled over. The entire shell script *and its documentation* fit on a post-it note.*

One-liners can look like inscrutable line noise. But if we can otherwise document them in a succinct way, does it really matter?

That's what this book does: provides solid explanations for extremely concise code. No matter what you do in Perl or your skill level, there's something in here for everyone.