[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] perl question
- Subject: [ale] perl question
- From: ecashin at noserose.net (Ed Cashin)
- Date: Mon, 16 Jan 2012 15:59:14 -0500
- In-reply-to: <[email protected]>
- References: <[email protected]>
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