in reply to Re: Variable scope in ternary ?: operator not propagating?
in thread Variable scope in ternary ?: operator not propagating?

Then how do you achieve the current effect of

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).

Replies are listed 'Best First'.
Re^3: Variable scope in ternary ?: operator not propagating?
by Aristotle (Chancellor) on Mar 16, 2003 at 00:04 UTC

    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.