my $x=42;
print "\$x before block: $x\n";
{
my $x=$x;
$x++;
print "\$x inside block: $x\n";
}
print "\$x after block: $x\n";
? (Should give 42, 43, 42.)
(Update: added missing $x++;, thanks, BrowserUk.)
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).
| [reply] [d/l] |
I suspect it will be by way of one of the new pseudopackages - as an educated guess, since all blocks are really closures in Perl 6, I'd say CALLER::. So my $x = $CALLER::x; will probably do that.
Or I may be entirely wrong. :-)
Makeshifts last the longest.
| [reply] [d/l] |