Both arrays are (different) flat arrays of items. They contain references — the
same references. At least, references that point to the same thing. And if two variables hold a reference that points to the same thing, they're almost like aliases (different variables that act as if they're one and the same variable with a different name).
*
What you want to investigate is what they call a deep copy or deep cloning. I recall merlyn wrote a magazine article or two about them. See UR col 30.
Also check out Storable, a standard module that includes a function for deep copying: dclone.
p.s. The difference between variables containing the same reference, and aliases, is just this: only a direct full assignment to one of the variables, will break the interconnection. Let me give an example:
$x = { a => 1 }; # a reference
$y = $x; # a copy of a reference points to the same thing
$y->{a}++; # increments $x->{a}
$y->{b} = 3; # adds a hash item $x->{b}
$y = { c => 0 }; # breaks the connection between $x and $y
$y->{c}++; # no effect on $x
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.