Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: About this behavior

by Macphisto (Hermit)
on Apr 16, 2001 at 05:45 UTC ( #72738=note: print w/ replies, xml ) Need Help??

in reply to About this behavior
in thread NEWBIE Brain Teaser

Well, and someone please correct me if I mislead on this post,

If you think about the code:
foreach $each (@list) {
$each *= 2;
$newlist$i = $each;

From Programming Perl: Note that the loop variable becomes a reference to the element itself, rather than a copy of the element. Hence, modifying the loop variable will modify the original array.

The snippet loops through the contents of @list and as each cell gets looked at, it is assigned to $each. $each is then modified by multiplying by 2. Modifying $each, modifies the value in the shell, due to the way foreach is constructed in perl. I believe that is all correct. If I have made any mistakes ( other than grammar, and spelling ), someone please tell me.

Macphisto the I.T. Ninja

Everyone has their demons....

Comment on Re: About this behavior

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (17)
As of 2015-11-30 17:20 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (777 votes), past polls