in reply to Re: Re: Unusual Closure Behaviour
in thread Unusual Closure Behaviour
It's a good theory, and certainly what I thought when I first looked at it. But it's easy to see that this isn't true: try comparing
withsub foo{ my $x if 0; print "FOO: ", $x++, "\n"; } sub bar{ my $x if 0; print "BAR: ", $x--, "\n"; } foo, bar for (1..10);
sub foo{ print "FOO: ", $x++, "\n"; } sub bar{ print "BAR: ", $x--, "\n"; } foo, bar for (1..10);
I reckon the real reason is the explanation given by Abigail.
Now I don't think I would ever write my $x if 0 unless I wanted to get the sack for writing obscure code, but how about:
would that be difficult to understand? Would it carry on working in the future?sub STATIC_VARIABLE{ 0 } sub foo{ STATIC_VARIABLE && my $x; print "FOO: ", $x++, "\n"; }
-- iakobski
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Re: Unusual Closure Behaviour
by HyperZonk (Friar) on Jul 12, 2001 at 21:35 UTC |