On Mon, Aug 14, 2006 at 16:01:47 +0000, Luke Palmer wrote: > What do these do?
Intuition based answers:
> for 1,2 {
> my $code = {
> my $x;
> BEGIN { $x = 42 }
> $x;
> };
> say $code();
> }
I think the closure would be emitted equivalently to my $x = 42, or
perhaps $x is not in the BEGIN blocks scope at all.
> for 1,2 {
> my $code = {
> state $x;
> BEGIN { $x = 42 } # mind you, not FIRST
> $x++;
> };
> say $code();
> say $code();
> }
Again, assuming the BEGIN { } body is not even compile but it's side
effect is meaningful, this is the same as
state $x = 42;
but starting to get a little tougher to justify.
Perhaps it does that, but also emits a warning e.g. 'implicit
initial value for future-scoped lexical' or something like that.
> for 1,2 -> $x {
> END { say $x }
> }
undef, because END is like a declaration putting the closure in some
global, and doesn't actually happen at runtime.
Otoh
for 1,2 -> $x {
state $y = $x;
END { say $y }
}
Might work
--
Yuval Kogman <[EMAIL PROTECTED]>
http://nothingmuch.woobling.org 0xEBD27418
pgp2ibIxnkvaI.pgp
Description: PGP signature
