|Perl: the Markov chain saw|
Duh. 'my' scope in if else blocks.by gam3 (Curate)
|on Dec 10, 2007 at 22:11 UTC||Need Help??|
gam3 has asked for the
wisdom of the Perl Monks concerning the following question:
I was running some code today with warnings on (using 5.8.8) and I noticed something new.
I did not know that the following code was correct:
I had thought that the scope of $t was only the if block and did not extend to the else blocks. Of course it makes perfect sense now. I just thought I would mention it here on the off chance that there is some other perlmonk as ignorant as me.
BTW I noticed this because I was running with use warnings, something I don't normally do.
This gives the warning:
"my" variable $a masks earlier declaration in same scope at ...
A picture is worth a thousand words, but takes 200K.