Obscure stuff indeed. I think that Abigail was indeed
correct. I suppose I should have actually tested my
hypotheses in code, like you did. <blush>
It seems that, despite what the perlref docs seem to say,
the scoping of the variable is done at compile time, but
the variable's reinitialization is done at run-time. Well,
I guess we should expect at least the first since it is a
lexical, right?
In any case, because of the compile-time scoping, we end up
with a local via
my no matter if the line
in which it is declared will ever run or not. But the
initialization never runs because of the permanently false
conditional at the point at which the run-time must run
initialization code. Actually, I suspect that we should
expect this behavior because data scoping is easily done at
compile, but initialization must be done at run-time.
Now, I think that this could be considered a feature for
those savvy to this rather bizarre behavior. And I like the
recommended usage from iakobski. But I would put a comment
in at the
STATIC_VARIABLE declaration, in case
the script needs to be maintained by a non-monk.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.