sub a { state $x; my $y; my sub b { state $z ; return $x++ + $y++ + $z++ ; } return &b; # is a \ before &b needed? }
will all &b refer to the same $z ?
yes, they will
does it mean that this is legitimate
sub a { state $x; my $y; state sub b { state $z ; return $x++ + $y++ + $z++ ; } return &b; # is a \ before &b needed? }
No, since you can't refer to $y in that sub (perl 5 actually allows you to do that but gives a warning 'Variable "%s" will not stay shared' - but I hope perl 6 will simply give a compile-time error)
-- Matthijs van Duin -- May the Forth be with you!
