in reply to Simple Noob Question
Unfortunately for you, you’ve stumbled into a bit of “Perl golf.” Such code is easy-to-read for the initiated, but quite confusing otherwise. I routinely re-write such code, or at least add comments directly above it. Your questions are entirely reasonable... because the code, as written, doesn’t expressly tell you.
Perl has many “predefined variables,” and it allows you to write code that omits any explicit reference to any variable, in which case the code is understood by Perl to implicitly reference certain of those variables. One of those variables is $_, which is, basically, “the last thing that was read or referenced.” (See the perldoc topics previously referred-to in other replies.)
Further complicating the situation is Perl’s use of “contexts.” In other words, it means something when you use $ vs. @ vs. %, and this meaning is sometimes quite arcane unintuitive.
Mind you, “I come neither to praise Caesar, nor to bury him,” but merely to describe him. My comments here are merely meant to be “factual, descriptive, and neutral.” You will encounter code like this, and in time, you may find yourself writing code like this, and “so be it.” Certain aspects of the Perl language rely upon knowledge of the subtleties of the language ... subtleties which are, some might argue (and some might dispute) are the language’s greatest strengths. It does bring you a bit of a learning curve that you might not have expected, and a bit more of a learning curve than you might have wished for. But these things, too, shall pass.
Welcome to the Monastery, and to the Perl community. Come here often. Ask away.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple Noob Question
by Anonymous Monk on Mar 04, 2011 at 14:05 UTC |