<br><br><div class="gmail_quote">On 26 July 2011 16:27, Toby Corkindale <span dir="ltr"><<a href="mailto:toby.corkindale@strategicdata.com.au">toby.corkindale@strategicdata.com.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 26/07/11 16:07, Mathew Robertson wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi all,<br>
<br>
As a result of some hacking on some code, I identified some quirky<br>
behaviour with regards to 'local'...   I have whittled the problem down<br>
to it simplest form - see below.<br>
<br>
Basically speaking, I would have expected the inner-array-variable to<br>
become localised to block scope.  Is there something that I am missing here?<br>
</blockquote>
<br></div>
What is happening here is a quirk of how Perl does multi-level data structures..<br>
<br>
$HANDLERS{c} contains a reference to an array.<br>
When you localise $HANDLERS{c} you are localising the value of that reference.. not the actual data in the referenced thing.<br></blockquote><div><br></div><div>Indeed that looks to be the case... which is why in the posted example, I also attempted to the use the localised dereferenced array (commented out), but to no avail as I am probably localising the array ref.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
You can achieve the result you're looking for with this mess:<br>
<br>
use Storable qw(dclone);<br>
{<br>
  # local $HANDLERS{c} = $HANDLERS{c};<br>
  local $HANDLERS{c} = dclone($HANDLERS{c});<div><div></div><div class="h5"><br>
  push @{$HANDLERS{c}}, 'u';<br>
  print Dumper(\%HANDLERS);<br>
}<br></div></div></blockquote><div><br></div><div>Not directly related the original question, but somewhat relevant I guess.... How does Storable::dclone compare to Clone::clone ?</div><div><br></div><div>regards,</div><div>
Mathew</div></div>