On Mon, Jan 16, 2012 at 2:45 PM, Geoffrey Myers <span dir="ltr">&lt;<a href="mailto:lists@serioustechnology.com">lists@serioustechnology.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Okay, so why is it that $foo is empty inside the sub bar() ??<br></blockquote><div><br>I think the key is &quot;its own copy&quot; in this paragraph from the perlfunc manpage:<br><br>       Unlike dynamic variables created by the &quot;local&quot; operator, lexical<br>
       variables declared with &quot;my&quot; are totally hidden from the outside world,<br>       including any called subroutines.  This is true if itās the same<br>       subroutine called from itself or elsewhere--every call gets its own<br>
       copy.<br><br>Keep in mind that the my $foo inside of the bar function is created when the file is parsed, before the for loop runs.  Setting the values initially helps me see what&#39;s going on in your example, as does &quot;perl -w&quot;.  If I understand the question completely, I think if you play with closures some you will feel completely comfortable with this.<br>
</div></div><br>-- <br>  Ed Cashin &lt;<a href="mailto:ecashin@noserose.net">ecashin@noserose.net</a>&gt;<br>  <a href="http://noserose.net/e/">http://noserose.net/e/</a><br>  <a href="http://www.coraid.com/">http://www.coraid.com/</a><br>