<?xml version="1.0" encoding="windows-1252"?>
<node id="578803" title="Re^4: The difference between my and local" created="2006-10-17 11:11:26" updated="2006-10-17 07:11:26">
<type id="11">
note</type>
<author id="381608">
ikegami</author>
<data>
<field name="doctext">
&lt;p&gt;As you've already been told (by Perl and by fellow monks), you can't use &lt;c&gt;local&lt;/c&gt; on a lexical (&lt;c&gt;my&lt;/c&gt;) variable.

&lt;p&gt;Fellow monks have shown how you can achieve your goal using &lt;c&gt;my&lt;/c&gt; instead of &lt;c&gt;local&lt;/c&gt;. If you had to use &lt;c&gt;local&lt;/c&gt;, then you need to make a package variable by that name first.

&lt;c&gt;
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";
&lt;/c&gt;

&lt;p&gt;You should never have to use this, though. Always use &lt;c&gt;my&lt;/c&gt; if possible.
</field>
<field name="root_node">
94007</field>
<field name="parent_node">
578736</field>
</data>
</node>
