I am new to perl and am confused with the rules for defining perl after writing the code snippet below:
my $i = 0;
foreach $i(5..10){
print $i."\n";
}
print "Outside loop i = $i\n";
I expected the output to be like this:
5
6
7
8
9
10
Outside loop i = 10
But its provision:
5
6
7
8
9
10
Outside loop i = 0
Thus, the value of the variable $ i does not change after the loop exits. What's going on here?
source
share