|go ahead... be a heretic|
Re: Array of variablesby Laurent_R (Parson)
|on May 28, 2013 at 21:28 UTC||Need Help??|
I am afraid that talking about references is taking the OP far too much forward at this point. It seems to me that the question is much more basic
To the OP: when you assign the array this way:@arry = ( $one, $two, $three );
Your are not putting these three variables into the array. You are putting into the array a copy of the current value of these variables at the time you do the assignment. So that, after this assignment, you array does not contain $one, $two and $three, but just their value, i.e. 1, 2 and 3.
If you modify any of the three variables afterwards, this will not modify the elements of the array.
Just to give another simpler example of the same thing:
On the second line, $d is assigned the value of $c at the time of the assignment, i.e. 3. $d is now a copy of the value of $c at the time of the assignment. Next line, $c is modified to 4. But this has no impact on $d, which has been given the value 3. This is exactly the same thing with your array.
This is very basic programming. If a variable is assigned to another variable, it takes the value of the variable that is current at the time of the assignment. Modifying later the other variable has no impact on the first variable.
You will learn later that it is possible to have the behavior that you were sort of expecting, this is what references are all about, but this is a more advanced topic that you probably don't want to study right now.