Why is there no warning thrown for the redeclaration of $i
in the following code?
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
You would get a warning if you redeclare a my
, our
or state
variable in the current scope or statement. The first $i
isn't actually a lexical variable. You can prove this using Devel::Peek
:
use Devel::Peek;
for my $i (1) {
Dump $i;
}
SV = IV(0x81178c8) at 0x8100bf8
REFCNT = 2
FLAGS = (IOK,READONLY,pIOK)
IV = 1
There's no PADMY
flag in FLAGS, which would indicate that $i
is a lexical variable, declared with my
.