I've tried changing the name of the array but does'nt work.I just ca'nt understand why updating this array will affect another array of a different name

Because a name don't mean much when you're modifying references. Example

my @foo = 1 .. 4; my @bar; my $someReference = \@foo; $bar[0] = $someReference; $bar[1] = \@foo; $bar[2] = $foo[2]; use Data::Dumper; print Dumper( \@bar ),"\n"; $bar[0][0]='change'; $bar[2] .= ' foo '; print " bar[0][0] ", $bar[0][0], "\n"; print " bar[1][0] ", $bar[1][0], "\n"; print Dumper( \@bar ),"\n"; __END__ $VAR1 = [ [ 1, 2, 3, 4 ], $VAR1->[0], 3 ]; bar[0][0] change bar[1][0] change $VAR1 = [ [ 'change', 2, 3, 4 ], $VAR1->[0], '3 foo ' ];
Make a change to $bar[0][0], and you're also changing $bar[1][0] because they are one and the same. It doesn't matter if you rename @bar to @barbar if you still asing $bar[0] and $bar[1] the same reference.

See perldata,perlref,perldsc... and perlmonks own Tutorials


In reply to Re: Updating 1 array affects the other array by Anonymous Monk
in thread Updating 1 array affects the other array by iphony

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.