http://www.perlmonks.org?node_id=678044


in reply to Re: **HomeWork** Printing the found input from an array
in thread **HomeWork** Printing the found input from an array

# works as expected!

Which depends on you expectations:

my @myCities = (1 .. 2); my $city = "before"; # now is scoped to the whole package! foreach $city ( @myCities ) { # do your stuff $city = "after"; } print "$city"; # works as expected! # ... unless you expected it to print "after" # ... actually it prints "before"

This is a Perl peculiarity I was once also bitten by.

Actually Perl will localize the $city for the scope of the for-loop. See perldoc perlsyn.