Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I would expect the $var lexical variable to be undef on each iteration in the following code snippet, where as it's not the case. The following example will print:
----Use of uninitialized value in concatenation... 555 555
for (1..3) { my $var = '' if 0; print STDERR "$var\n"; $var = 555; }
My question is: is this "by design" for the lexical variable defined in this way, to keep the value from previous iteration. Shouldn't the "padlist" be cleared on each iteration?
20071101 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lexical scope variable is not undef'ed
by FunkyMonk (Bishop) on Oct 22, 2007 at 16:37 UTC | |
|
Re: Lexical scope variable is not undef'ed
by ikegami (Patriarch) on Oct 22, 2007 at 16:46 UTC | |
by grinder (Bishop) on Oct 22, 2007 at 17:46 UTC | |
by ikegami (Patriarch) on Oct 22, 2007 at 17:51 UTC | |
|
Re: Lexical scope variable is not undef'ed
by Anonymous Monk on Oct 22, 2007 at 17:44 UTC | |
by tilly (Archbishop) on Oct 23, 2007 at 00:34 UTC | |
|
Re: Lexical scope variable is not undef'ed
by gamache (Friar) on Oct 22, 2007 at 16:46 UTC | |
by ikegami (Patriarch) on Oct 22, 2007 at 16:53 UTC |