Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
There's more than one way to do things
 
PerlMonks  

Re: Re: Re: Re: Unusual Closure Behaviour

by HyperZonk (Friar)
on Jul 12, 2001 at 21:35 UTC ( #96123=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Unusual Closure Behaviour
in thread Unusual Closure Behaviour

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.


Comment on Re: Re: Re: Re: Unusual Closure Behaviour
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://96123]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2014-04-17 19:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (454 votes), past polls