<?xml version="1.0" encoding="windows-1252"?>
<node id="665082" title="Re^2: What's wrong with this local() ? (*)" created="2008-01-30 03:14:12" updated="2008-01-29 22:14:12">
<type id="11">
note</type>
<author id="22609">
tye</author>
<data>
<field name="doctext">
&lt;p&gt;
Actually, it is closer to:
&lt;/p&gt;&lt;c&gt;
# Save a reference to the original variable:
*nothingToSeeHere::var= \$var;
# Replace the variable with a new variable instance and assign
# that new instance the given value (or undef if none mentioned):
*var= \undef; # (but see footnote)
# Restore the previous instance (and thus the previous value):
ON_SCOPE_EXIT { *var= \$nothingToSeeHere::var; }
&lt;/c&gt;&lt;p&gt;
That is, it is not just the value that is saved, but the scalar that holds that value.  This can matter if the variable was [tied] or has other "magic" attached to it.  It also matters if you have taken a reference to the original instance of the variable or take a reference to the new instance (they will point to different variables).  It also means that the string value is not copied, as would happen with &lt;c&gt;$saved= $var;&lt;/c&gt;.
&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-22609"&gt;&lt;p align="right"&gt;
- [tye]&lt;tt&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/tt&gt;
&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;
&lt;sup&gt;*&lt;/sup&gt; Actually, this step is less like &lt;c&gt;*var= \undef;&lt;/c&gt; (which leaves $var read-only) and perhaps more like &lt;c&gt;*var= do { my $t= undef; \$t };&lt;/c&gt;.  But testing shows that the latter leaves $var marked "PADBUSY" and "PADMY" so it is perhaps even more like &lt;c&gt;*var= \[undef]-&gt;[0];&lt;/c&gt;.  Go figure. :)
&lt;/p&gt;
</field>
<field name="root_node">
665045</field>
<field name="parent_node">
665054</field>
</data>
</node>
