Both Higher-Order Perl: Transforming Programs with Programs (shortened to HOP in this article), by Mark Jason Dominus and Randal Schwartz's Perls of Wisdom (shortened to RSPW in this article), by Randal Schwartz have some things in common. Obviously, they are both about Perl, and their authors are well known in the Perl community. In addition, both books are collections of interesting techniques for Perl rather than discussions of a single software package.
There are important differences, however. RSPW is a loose collection of articles with little more in common than the author himself. They are all interesting, but the author did not write them to a single purpose, and the book is more in the style of The Perl Cookbook than most other Perl books. HOP, on the other hand, is a text sure to become a classic; it starts with moderately difficult Perl techniques and builds up to possibly the most complex yet enlightening examples I've ever given the chance to melt my brain.
See the Resources section for links to all books mentioned in this article.
Mark Jason Dominus is well known in the Perl community, and deservedly so. HOP showcases his skill and numerous exciting techniques.
Chapter 1 in HOP opens with simple topics like recursion and callbacks, always backed by good examples. Even tangential topics such as
non-reentrant functions are paid the attention they deserve. Chapter
2 covers dispatch tables. The configuration examples are great,
but should have mentioned modules like AppConfig that automate
much of the work. (Although the examples do things AppConfig can't,
most programs don't need those advanced functions.)
Chapter 3 deals with memoization, a technique for caching functions' results (at the expense of memory to store those results). This thorough chapter covers all the bases: explanation, examples, advantages and disadvantages, typical problems with memoization, and so on. Once the chapter goes into lexical closures (3.5.2), most beginner programmers will probably decide it's time to put the book aside and wait awhile before tackling it again. This is no "Learning Perl" material; at least a few years of programming experience are necessary to get through the rest of the book. The Orcish Maneuver (3.10) is covered nicely, and the semipredicate problem is there too (I knew the problem before reading HOP, but not by name, and it was nice to see it explained).
The general feel of the book by now is one of a computer science professor, who happens also to be a Perl expert, having a leisurely one-on-one conversation with a student. This is different from most Perl books, which are written more as one programmer to another. HOP reads more like a book and less like a series of how-to snippets. It worked for me, but it might not work for the less patient. Chapter 3 is a turning point -- if you don't enjoy and understand everything in it, the rest of HOP is not for you.
Chapter 4 starts building the iterator framework that underlies the rest of the book. It's essential to any programmer interested in this cool pattern, and the examples progress from simple to "Mr. Dominus, you're crazy" (in the complimentary sense). Filters and transforms on iterators build on each previous example to show code patterns that are immediately useful in the real world.
Chapter 5 deals with partitioning problems, converting recursive functions to iterative functions (it's fun, I assure you), and more factorial and Fibonacci series implementations. Chapter 6 is about infinite streams; I couldn't finish it, it just went on and on (okay, joking!). Section 6.5 deals with regular expression string generation, which is a commonly asked question: "Given a regular expression, how do you find all the strings that match it?" This is, of course, impossible in many cases, but there are times where the result set is finite, and in other cases the beginning of the infinite stream of solutions is all you need.
Chapter 8 is the heart of the book, implementing functions that operate on other functions (higher-order functions, possibly the reason for the title of the book). Each section and example is vital to the rest of the book. Lexing and parsing through the HOP framework are introduced and developed. This is where your brain will start smoking. Take a break and come back rested. Chapter 9 continues with the wonderful, complex examples and implements a declarative drawing system.
In many years of programming experience, only a few books have enriched my programming skills in every way, as this one has. The others I can think of immediately are Unix Power Tools, the Stevens books on UNIX® programming, and of course the several volumes of The Art of Computer Programming by Knuth. These books don't just teach a language, they teach a philosophy and do it well. I hope this conveys my admiration and respect for Mark Jason Dominus and HOP. HOP will stay on my bookshelf for a very long time.
Randal Schwartz's Perls of Wisdom
RSPW is a fun book. Whereas HOP is a trip through the halls of computer science on a Perl motorcycle (noise and all), RSPW is a bus ride in the country. The articles in RSPW range from current to outdated, mostly because they inspired new CPAN modules or developments in Perl itself. Randal writes well, and the articles are clear and concise. They often miss an "if you like this, see CPAN module XYZ" note. For example, the templating article in Chapter 4 (CGI Programming) should have mentioned the Template Toolkit, which does much more than the article implements.
Chapter 1 is a mix of advanced Perl tutorials. They are all worth reading. The "Introduction to Objects" tutorial is especially good.
Chapter 2 covers text searching and editing, Perl's traditional strengths. Again, every article is worth a look and most will be useful to you. They range from beginner to intermediate-level content, and flow easily.
Chapters 3, 4, and 5 are mostly about Web development (HTML and XML, CGI, Webmaster's Toolkit). This is the heart of the book and Randal's main interest. As the comment to one article says, they were written in response to a real-world problem, and it shows. The code is sometimes unpolished, sometimes too specific, but it's always useful, and the article itself simply builds up to the code, presenting it with an explanation.
RSPW addresses a different audience from the readers of HOP: mostly beginner to intermediate Perl programmers looking for practical, immediately usable code. Its only fault is that it does not comment on existing CPAN modules that could replace that code and save the reader the work. In every other way, RSPW is a good book that I would heartily recommend together with The Perl Cookbook and Programming Perl.
In sum, both HOP and RSPW are good additions to a library -- but probably not the same library.
RSPW is a great beginner book, full of useful advice and detailed code explanations. It is highly enjoyable (if you don't like or understand an article, you can just skip it!) and immediately usable in the real world.
HOP is a terrific book targeted at the advanced Perl programmer with a significant computer science background. If you took an algorithms class in college and enjoyed it, and you feel very comfortable writing Perl, you will probably love HOP. The tone, content, and code make HOP memorable; the knowledge, wisdom, and intuition it provides make it a book any Perl programmer should aim to understand and digest in full.
Learn
-
Read the books discussed in this article:
- Higher-Order Perl: Transforming Programs with Programs (Morgan Kaufmann, March 2005) by Mark Jason Dominus
- Randal Schwartz's Perls of Wisdom (Apress, December 2004) by Randal Schwartz
- Perl Cookbook (O'Reilly, August 2003) by Tom Christiansen and Nathan Torkington
- Unix Power Tools (O'Reilly, October 2002) by Shelley Powers, Jerry Peek, Tim O'Reilly, and Mike Loukides
- Books by Richard Stevens (various publishers and publication dates)
- The Art of Computer Programming series (Addison-Wesley, various publication dates) by Donald E. Knuth
-
Read Ted's reviews of Perl 6 Essentials, Perl Cookbook, and Perl Template Toolkit in "Cultured Perl: Three essential Perl books" (developerWorks, May 2004).
-
Read all of Ted's Perl articles in the Cultured Perl series on developerWorks.
-
In the developerWorks Linux zone, find more resources for Linux developers.
-
Stay current with developerWorks technical events and Webcasts.
Get products and technologies
-
CPAN, the Comprehensive Perl Archive Network, is the main source for Perl modules, scripts, documentation, and more.
-
Order the SEK for Linux, a two-DVD set containing the latest IBM trial software for Linux from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.
-
With IBM trial software, available for download directly from developerWorks, build your next development project on Linux.
Discuss
-
Check out developerWorks
blogs and get involved in the developerWorks community.

Teodor Zlatanov graduated with an M.S. in computer engineering from Boston University in 1999. He has worked as a programmer since 1992, using Perl, Java, C, and C++. His interests are in open source work on text parsing, 3-tier client-server database architectures, UNIX system administration, CORBA, and project management.
Comments (Undergoing maintenance)





