|
|
| Syntactic Confectionery Delight | |
| PerlMonks |
Re^3: Update referencesby Eliya (Priest) |
| on May 13, 2012 at 22:29 UTC ( #970353=note: print w/ replies, xml ) | Need Help?? |
|
But it looks like I can't replace that piece of data by modifying the original array. Of course you can, but you must not destroy the internal reference of the array slot [0] to the scalar originally stored in it. If you do so, you have no access to that scalar any longer via $a[0]. Change @a = ('a','b','c') to pop @a; @a[0..2] = qw(a b c); and things will work fine. In the former case, 3 new scalars are being placed into the array slots, while in the latter case, the old scalars are being modified.
Your misunderstanding is that you think Perl works like C, i.e. that references directly point to the memory locations where the actual data is stored. This is not how Perl works.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||