laziness, impatience, and hubris | |
PerlMonks |
Re: What is %_by ikegami (Patriarch) |
on Sep 29, 2015 at 18:32 UTC ( [id://1143359]=note: print w/replies, xml ) | Need Help?? |
%_ is a hash. You can have a hash named _ because _ is a valid name for a variable. (I'm sure you are familiar with $_ and @_.) No Perl builtin currently sets it or reads it implicitly, but punctuation variables are reserved. "Perl variable names may also be a sequence of digits or a single punctuation or control character (with the literal control character form deprecated). These names are all reserved for special uses by Perl" Punctuation variables can't be declared as lexical variables, which is why my %_; is failing. As with other punctuation variables, the best you can do is local %_;. Keep in mind that use strict; won't help remind you of the need to do this, so it's more error prone than using a non-punctuation variable. Punctuation variables are also special in that they are "super globals". This means that unqualified reference %_ refers to %_ in the root package, not %_ in the current package.
This means that forgetting to use local %_ can have very far-reaching effects.
In Section
Seekers of Perl Wisdom
|
|