Higher-Order Perl

by Mark Jason Dominus

Order Higher-Order Perl online from Powell's Books

Download full text

Current Status: The book was published on 8 March 2005. Copies are now available in bookstores in the U.S. and Europe, and from online booksellers. A second printing became available in August 2005.


**NEW** A Chinese-language edition of HOP, translated by Mr. Teng Jiahai, was published in June 2013 by China Machine Press and is available from Chinese-language online booksellers.

Idea of the Book

Higher-Order Perl is about functional programming techniques in Perl. It's about how to write functions that can modify and manufacture other functions.

Why would you want to do that? Because that way your code is more flexible and more reusable. Instead of writing ten similar functions, you write a general pattern or framework that can generate the functions you want; then you generate just the functions you need according to the pattern. The program doesn't need to know in advance which functions are necessary; it can generate them as needed. Instead of writing the complete program yourself, you get the computer to write it for you.


Table of Contents

  1. Recursion and Callbacks
  2. Dispatch Tables
  3. Caching and Memoization
  4. Iterators
  5. From Recursion to Iterators
  6. Infinite Streams
  7. Higher-Order Functions
  8. Parsing
  9. Declarative Programming

HOP is full of useful and interesting examples that Perl programmers will want to see. Chapter 1 is about writing recursive functions to walk the file system and to process recursively-structured data such as HTML documents. Chapter 2 discusses dispatch tables in the context of reading configuration files. Chapter 4 concludes with an improved replacement for the WWW::SimpleRobot module, with better functionality in one-third the code, and also contains a basic database query system that searches an HTTP log file backwards, delivering the most recent records first. Chapter 6 discusses the frequently asked question of how to generate a list of all the strings that will match a given regex and provides an astonishingly simple solution. Later on, in Chapter 8, I show how to build a parser for regexes and attach it to the string generator. Chapter 9 presents linogram, a complete constraint-based diagram-drawing system.


HOP is available for free

It is here. You can download the publisher's final PDF proofs for the second printing, or you can download my uncorrected manuscript copy in MOD format.

Sorry for the delay. I hoped to have it posted by the end of 2005. Oops.

You can also use this full-text search to search the book.

About the Title

For a long time, the provisional title of the book was "Perl Advanced Techniques Handbook". We never planned to use this title; we always planned to change it once we found something better.


Mailing Lists

mjd-book: I used to send occasional reports of my progress on HOP this mailing list. I have not sent any announcements since HOP was published, but it is possible that I will send some in the future, for example if a translation of the book is published. This list is extremely low volume. It is quite possible that it will never see another message. Complete archive of past messages.

mjd-books: I am working on at least one more book. For announcements about this upcoming book and any other books I might write in the future, subscribe to this list. Subscribers get to see draft chapters, course materials related to my books, and other goodies. This list is low-volume. Complete archive of past messages.

hop-discuss: A public discussion list for HOP-related matters. Complete archive of past messages

hop-discuss-digest: Digest version of hop-discuss. Instead of one message at a time, this list receives the messages in batches, every few days.

hop-volunteer: **NEW** Would you like to help me put HOP online? Please read the archived messages and subscribe here.

To subscribe to any of these lists, send mail to:

or submit this form:

Subscribe to:
mjd-book mjd-books hop-discuss hop-discuss-digest hop-volunteer
Your email address:

Order Higher-Order Perl online from Barnes & Noble


Return to: Mark Dominus blog | What's new page | Perl Paraphernalia

mjd-perl-hop+@plover.com