Skip to main content

Cultured Perl: Perl books, Part 1

A look inside Higher-Order Perl and Randal Schwartz's Perls of Wisdom

Teodor Zlatanov (tzz@bu.edu), Programmer, Gold Software Systems
Author photo
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.

Summary:  Take a tour of two solid additions to any Perl library, the beginner-oriented Randal Schwartz's Perls of Wisdom by Randal Schwartz, and the more advanced Higher-Order Perl by Mark Jason Dominus. Read all of the columns in Ted Zlatanov's Cultured Perl series.

View more content in this series

Date:  15 Mar 2006
Level:  Introductory
Activity:  2330 views

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.

Higher-Order Perl

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.

Summary

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.


Resources

Learn

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

About the author

Author photo

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)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Linux, Open source
ArticleID=105857
ArticleTitle=Cultured Perl: Perl books, Part 1
publish-date=03152006
author1-email=tzz@bu.edu
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers