in reply to RE: Re: Efficient Perl Programming
in thread Efficient Perl Programming

I don't think that "a compendium of elegant Perl idioms" will be a good description of the Perl Advanced Techniques Handbook. When people talk about 'idioms' they usually mean one- or two-line snippets like the one fastolfe mentioned that pre-extends a hash. But PATH isn't going to be about that at all.

The idea of PATH is that there are a lot of powerful programming techniques that are possible in Perl but not in other languages that Perl programmers are familiar with. Since Perl programmers haven't seen these techniques before, they don't know how to use them, what they are good for, or even that they exist, and they are letting a lot of the power and expressiveness of Perl go to waste. The techniques are not little things like pre-extending a hash. They are much bigger ideas that apply to the organization of entire programs, ideas on the scale of 'object-oriented programming'.

One example is the idea that in Perl you can write a function that manufactures other functions. Instead of writing a lot of similar functions in the source code, you instead write one function which, when called, generates the function that you actually want to use and returns it. By invoking this 'function factory' with different arguments, your program can manufacture as many functions as it needs to without your having to guess in advance what all the functions will need to do.

Perl's own sort operator is a limited example of this. If sort only sorted lists alphabetically, it would only bone ten-thousandth as useful as it is. But instead, it gets an argument, supplied by the programmer, which tells it how to compare two list elements. In effect, this extra argument transforms sort into a different function, which sorts lists in the way that the programmer specified; if you give it a different argument, you get a different kind of sorting function back out.

This is tremendously useful in the case of sort, but most Perl programmers don't realize that they can apply the same techniques to their own functions in many similar circumstances and make their own functions much more useful and general than they would have been otherwise.

Anyway, if you're interested, the correct URL is http://perl.plover.com/book/.