The Perl Jargon : cops

rafael on 2003-06-22T19:52:58

Continuing our etymological exploration of perl's internals jargon... (NB. I'm not trying to produce some reference work here -- but rather to have some fun with some of the words that appeared in the perl dialect.) Today, as promised : What's a cop ?

In real life, you know what's a cop, don't you. Let's take traffic cops for example. Their job is, abstractly, to regulate the flow of cars. Well, in perl, that's the same thing. More or less. cop, in perl, stands for Control OPeration.

In more detail : when perl interprets a Perl script, it first compiles it into a syntax tree, in which nodes are called operations (or ops for short). Each op corresponds to a basic operation of the runtime interpreter : addition, file opening, method call, etc. and there are many types of ops (unary, binary, list...) A cop basically corresponds to a semicolon in a perl source code : it's a checkpoint between two separate statements. At each control op, perl stores the current source file name and line number, the compiler hints (e.g. which set of strictures are in effect), the current lexical warnings in use, a potential loop label, etc. So cops, well, passively regulate control flow. (OK, they're more like roadsigns than actual cops. Anyone wants to propose a better parallel?)


Thanks!

Dom2 on 2003-06-23T09:47:49

I really appreciate these; they're very useful.

-Dom