http://qs321.pair.com?node_id=274781


in reply to $_ scoping issues

When you do foreach (list_of_stuff), $_ is aliased to each entry in the list in turn. Hence, $_ *is* $u->{loc} and has the same address.

If you want to copy each list element into another variable for processing (which is generally the wise thing to do) the usual solution would be foreach my $foo (list_of_stuff).

On an unrelated issue, I betcha that foreach ($u->{loc}) is a bug. $u->{loc} is, and always will be, a scalar, so there's no point in the foreach.