in reply to Scoping of my with foreach loop
The difference can be observed by running the following two snippets.
use strict; my @array = (1, 2, 3); my $item = 'z'; foreach $item (@array) {} print($item); # Prints 'z' (not '3'!!!).
use strict; my @array = (1, 2, 3); foreach my $item (@array) {} print($item); # Compile error. $item only in scope for loop.
|
|---|