in reply to Get the $main value when use local
I would recommend you just use lexicals. The cases where you want to use local() are very limited (generally, local is used for temporarily overriding special globals like $/, $_ etc).
If you really need to use globals, just do this:
$a='main'; if (1) { my $olda = $a local $a = 'sub'; print "$a\n"; print "$olda\n"; } print "$a\n";
|
|---|