IIRC, this also works:
$gold if 0;
It doesn't modify the var. It doesn't result in any run-time code at all.
Demo:
$ perl -Mv5.10 -we \ 'do { my $x = 42; sub { say eval q{$x} } }->()' Variable "$x" is not available at (eval 1) line 1. Use of uninitialized value in say at -e line 1. $ perl -Mv5.10 -we \ 'do { my $x = 42; sub { $x if 0; say eval q{$x} } }->()' 42
Update: Tested and added demo.
In reply to Re^3: trouble with packages/eval/variable-scoping
by ikegami
in thread trouble with packages/eval/variable-scoping
by Ratazong
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |