As I write the book Modern Perl, I keep looking for organizational principles and guidelines to govern what to discuss, what to leave out, and the metaphors and explanations I give. (I'm getting close to the point where I can post draft chapters for comments; if you're interested in reading and giving feedback, please contact me privately.)
The most important question I've asked so far is "What's the minimal amount of Perl knowledge necessary to prepare someone to write and understand Modern Perl effectively?" I've decided there are three facets.
- How to identify individual chunks of information in a single Perl statement. This is effectively the same type of behavior as diagramming sentences in a written language. You may not know exactly what
$$
means in the statement$pids->{$$}--
, but you should be able to recognize that$pids
refers to a scalar variable, that->{...}
performs a hash dereference of a single key, that--
is the postfix decrement operator, and that$$
is a scalar variable. - How to refer to the appropriate places of the Perl documentation to understand individual chunks. This is the Perl equivalent of using a dictionary to look up words you don't understand. You may know that squamous is an adjective when H.P. Lovecraft uses it, but to understand the sentence fully, you need to look in the dictionary. While some people claim that you have to understand all of Perl to read anyone else's code, I disagree. You have to be able to look up the parts you don't know.
- How to recognize and use common Perl idioms. The
while/readline/chomp
loop is one such idiom. So is the Schwartzian transform. So is the use of hashes for identifying set membership. (This suggests the existence of aperlidioms
document.)
While creating the outline for and writing the book, I've realized that I have to leave out more information than I can include. (This is most apparent when discussing regular expressions.) If, however, I can teach people these three facets, I believe I can prepare them to write and maintain Perl well.