in reply to Lexical scope variable is not undef'ed
Your problem is this statement:
Which is being parsed as:my $var = '' if 0;
...And in turn, the statement is skipped entirely. Therefore you are never creating a lexical variable $var -- you are implicitly using a local variable $var, which retains its value from iteration to iteration and then resets itself once the loop is exited.if (0) { my $var = ''; }
perlsyn explains it.
Example:
bash$ perl -e 'for(1..3){my $i if 0; print $i++, "\n"}' 0 1 2 bash$ perl -e 'for(1..3){my $i if 1; print $i++, "\n"}' 0 0 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Lexical scope variable is not undef'ed
by ikegami (Patriarch) on Oct 22, 2007 at 16:53 UTC |