[ale] perl question
Ed Cashin
ecashin at noserose.net
Mon Jan 16 15:59:14 EST 2012
On Mon, Jan 16, 2012 at 2:45 PM, Geoffrey Myers <lists at serioustechnology.com
> wrote:
> Okay, so why is it that $foo is empty inside the sub bar() ??
>
I think the key is "its own copy" in this paragraph from the perlfunc
manpage:
Unlike dynamic variables created by the "local" operator, lexical
variables declared with "my" are totally hidden from the outside
world,
including any called subroutines. This is true if itâs the same
subroutine called from itself or elsewhere--every call gets its own
copy.
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.
--
Ed Cashin <ecashin at noserose.net>
http://noserose.net/e/
http://www.coraid.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20120116/f4714fb3/attachment-0001.html
More information about the Ale
mailing list