use Devel::Peek;
my @array = (1,2,3);
Dump \@array;
print "====\n";
foreach (@array) {
Dump $_;
print "----\n";
}
Will output:
SV = RV(0x193de54) at 0x22593c
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x226680
SV = PVAV(0x22a95c) at 0x226680
REFCNT = 2
FLAGS = (PADBUSY,PADMY)
IV = 0
NV = 0
ARRAY = 0x19240d4
FILL = 2
MAX = 3
ARYLEN = 0x0
FLAGS = (REAL)
Elt No. 0
SV = IV(0x1926b90) at 0x225858
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 1
Elt No. 1
SV = IV(0x1926b94) at 0x225918
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 2
Elt No. 2
SV = IV(0x1926b98) at 0x225930
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 3
====
SV = IV(0x1926b90) at 0x225858
REFCNT = 2
FLAGS = (IOK,pIOK)
IV = 1
----
SV = IV(0x1926b94) at 0x225918
REFCNT = 2
FLAGS = (IOK,pIOK)
IV = 2
----
SV = IV(0x1926b98) at 0x225930
REFCNT = 2
FLAGS = (IOK,pIOK)
IV = 3
----
As you can see, the IVs printed in the for loop are the same ones from the array (same pointer value) but they now have a reference count REFCNT=2
This means that the IVs were referenced in the new list, so that's why modifying them there will also modify them in the array.
--
Leviathan.
|