On Mon, Jan 16, 2012 at 2:45 PM, Geoffrey Myers <span dir="ltr"><<a href="mailto:lists@serioustechnology.com">lists@serioustechnology.com</a>></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 "its own copy" in this paragraph from the perlfunc manpage:<br><br> Unlike dynamic variables created by the "local" operator, lexical<br>
variables declared with "my" 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's going on in your example, as does "perl -w". 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 <<a href="mailto:ecashin@noserose.net">ecashin@noserose.net</a>><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>