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:

my $c = 3; my $d = $c; $c = 4; print "$d \n"; # prints 3

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.


In reply to Re: Array of variables by Laurent_R
in thread Array of variables by rtteal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.