in reply to Two Questions on "my"
Okay, I was wrong about the not-getting-executed stuff. But can anyone explain what's going on with the second and third examples? It's almost as if the scope of the my were restricted to the statement it's used in and that the $foo getting printed and incremented is a different variable -- at least after the first time through the loop (if that even makes sense). But if that were the case, why didn't strict complain?use strict; foreach (0 .. 10) { my $foo; $foo = 0 unless $_; print $foo++, ' '; } 0 0 0 0 0 0 0 0 0 0 0 use strict; foreach (0 .. 10) { my $foo = 0 unless $_; print $foo++, ' '; } 0 0 1 2 3 4 5 6 7 8 9 use strict; foreach (0 .. 10) { my $foo = 0 unless $_; print $foo, ' '; $foo++ } 0 1 2 3 4 5 6 7 8 9
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Two Questions on "my"
by Somni (Friar) on May 24, 2004 at 05:44 UTC | |
by Dr. Mu (Hermit) on May 24, 2004 at 06:29 UTC |