Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://323696]
help
Chatterbox?
[Corion]: Yay. Traditional finance situation averted. Bonds can be quoted in amounts (1_000_000 EUR) or per unit (1 unit). And a traditional error is to trade 2_000_000 piece when you meant to trade 2_000_000 EUR.
[Corion]: (one of my scripts simply catches high amounts and I phone people making that trade, ideally before the payment is due)
[Corion]: The sad thing is that my script sits at the end of the pipeline and can only look at the payments due today or tomorrow basically, while there are many more systems further up in the pipeline
[GotToBTru]: better late than never, I guess
[Corion]: GotToBTru: Sure - there is a long and sad story of many frantic cleanups that led us to implement this notification ;)

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2017-03-29 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (347 votes). Check out past polls.