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


in reply to Variable scoping, foreach loop, alias

In your loop, $bla is being aliased to each element of the array in turn. So, when you modify $bla, you are really modifying the array element that $bla is referring to.

The same thing happens with $_ if you don't specify a variable. For example, try this as well:

my @arry = (1, 2, 3, 4); ++$_ for @arry; print "$_\n" for @arry;

-- Mike

--
XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
-- grantm, perldoc XML::Simpler

Replies are listed 'Best First'.
Re: (2) Variable scoping, foreach loop, alias
by Paulster2 (Priest) on Jan 23, 2004 at 21:18 UTC

    I didn't realize that it only became an alias. This explains a lot to me. I appreciate your two replies!! Thanx a lot zaxo and thelenm for the insight!

    Paulster2