http://qs321.pair.com?node_id=740513

Perl has a lot of features that are not immediately obvious to the casual observer. By "casual observer," I mean someone who sees the language "in the wild" but hasn't formally learned it. Think of the programmer who learns it by opening up some working Perl and modifying it.

Consider, as an example, split. Here's a typical invocation:

my @fields = split /:/, $record;

To the casual observer, there are three things that go with split: a record, a field separator, and someplace to put the separated fields. One could see a lot of Perl without ever seeing any variation on this usage.

Nevertheless, there are a lot of possible variations.

  • The $record is optional and defaults to $_.
  • The field separator is also optional and defaults to a special form of splitting on white space (leading white space is ignored).
  • The field destination is optional too. If split is used in a scalar (or void) context, fields go into @_ (clobbering your sub arguments, if you have any). If you have warnings on, you may also learn that, "Use of implicit split to @_ is deprecated."
  • There's an optional third argument (a number) that limits how many fields split is allowed to return.
  • If the field separator contains capturing parentheses, whatever is captured in them will be returned as a field.
  • If the field separator is a single space (' '), it invokes the special white space splitting feature that you get with no arguments.

Those are just the ones I know off the top of my head. A look at the split documentation shows other interesting special cases that I'm pretty sure I've never run into. I know at least some of the features I've listed above were present in Perl 4, and yet they still feel to me like afterthoughts.

(A better example of an "afterthought feature" might be the (?xxx) style features in modern regular expressions. Why do they always start with an open parenthesis and a question mark? I've always assumed it's because that would have been a syntax error in earlier versions of Perl. No earlier code could have been relying on (?xxx) to do anything meaningful, so it's safe to have later code use it for features the earlier Perl didn't have. Now we have lots of different things introduced by an open parenthesis and a question mark.)

I like these extra features. It's fun, like discovering a pocket you didn't know you had in a garment you've worn for years. Still, I wonder sometimes if Perl's casual observers are put off by these things. My guess is that it depends on one's attitude. Some are (as I am) delighted by discovering something new in something old. Others may be dismayed that they did not know the language as well as they thought and may even despair that they'll never master it as they'd like.

I think this is why the Perl community is so important. The monks welcome newcomers and guide them through the language. Experts can show the inexperienced what's in the dark corners and tell them when and why to go there. There are pitfalls, but at the Monastery, there's usually someone hanging around to direct the unwary away from them. In these and other efforts, the monks demonstrate an attitude that delights in discovery so that those without that attitude may witness it, learn of it, and perhaps take it as their own.