http://qs1969.pair.com?node_id=578803


in reply to Re^3: The difference between my and local
in thread The difference between my and local

As you've already been told (by Perl and by fellow monks), you can't use local on a lexical (my) variable.

Fellow monks have shown how you can achieve your goal using my instead of local. If you had to use local, then you need to make a package variable by that name first.

use strict; my $tt = 3.14159; { our $tt; local $tt = 3; print "In block, \$tt = $tt\n"; print "In block, \$::tt = $::tt\n"; } print "Outside block, \$tt = $tt\n"; print "Outside block, \$::tt = $::tt\n";

You should never have to use this, though. Always use my if possible.