Captures, memories, and clusters

Language evolves, Perl evolves, and Perl being the product of a linguist, the language of Perl evolves.

When I started using Perl, we didn’t have a formal name for the result of parentheses in a regular expression.

At first, we used forms of the word group to refer to the parentheses both as what they do and what they are. The first edition of Programming perl uses “group”, but the first five editions of Learning Perl use the term memory. That’s the term I used (and still tend to use) in Perl classes for years.

The documentation for Perl 5.004, released throughout 1997, shifts to using the terms captures and clusters. That’s before the second edition came out.

Part of this change was the addition of grouping-only parentheses in Perl 5.000. The (?:PATTERN) groups but does not remember:

my $string =~ m/abc(?:...)xyz/;

With that feature, we need two words to distinguish between their actions. Calling it a “capture” means it sets the match variables $1 and so on (although a successful match with no captures will clear those variables). Calling it a “cluster” means we’re doing it for precedence or to apply a quantifier, anchor, or alternation to the entire group.

Now the sixth edition is coming out, so we’re switching from “memory” to “capture”. It’s taken us awhile, but we’re up to date with the jargon now.