Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Variable scoping, foreach loop, alias

by thelenm (Vicar)
on Jan 23, 2004 at 21:11 UTC ( #323696=note: print w/ replies, xml ) Need Help??

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

Comment on Re: Variable scoping, foreach loop, alias
Select or Download Code
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!


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://323696]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (16)
As of 2015-03-27 15:55 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (612 votes), past polls