Higher-Order Perl

Mark-Jason Dominus, Chief Programmer, Plover Systems Co.

Track: Perl
Date: Monday, July 24
Time: 1:30pm - 5:00pm
Location: Portland 255

One of the most powerful techniques available to Perl programmers is writing functions that can manufacture or modify other functions. Instead of writing ten similar functions that must be maintained separately, you can write a single function that will create the others as needed. This class will teach you how.

The first section concerns the technique of dynamically replacing functions with facades. Without changing a function's code, we can add caching behavior to it, or have it enforce an interface contract, or automatically track its own performance.

The second section concerns iterators, which are functions for generating data a little bit at a time. For files, provides filehandles, but the technique is more generally applicable. As with filehandles, the technique is suitable when the total amount of data is too large to use all at once. This section ends by implementing an improved version of Perl's standard File::Find module. Unlike the usual implementation, the improved version can be stopped in the middle and resumed later as often as desired. Multiple searches can be active simultaneously, making it possible to recursively compare two separate directory structures.

The final section concerns parsing. Perl's built-in utilities make it easy to parse simple inputs, but for more complex data a modular approach is more effective. A basic parser is a trivial function that transforms a simple input into a value. By writing functions that build more complex parsers from simple, interchangeable parts, we can easily built up a parser for any kind of input.