in reply to Re: Update references
in thread Update references

The reference refers to the scalar retrieved via $a[0], not the array index [0].  The reference knows nothing about the array that scalar came from.  And the scalar will exist as long as its refcount is > 0.

$ perl -MDevel::Peek -E'@a=qw(a b c); $r=\$a[0]; Dump $r; @a=(); Dump +$r' SV = IV(0xa95bc0) at 0xa95bd0 REFCNT = 1 FLAGS = (ROK) RV = 0xa77998 SV = PV(0xa75c20) at 0xa77998 REFCNT = 2 <--- FLAGS = (POK,pPOK) PV = 0xa8ee40 "a"\0 CUR = 1 LEN = 16 SV = IV(0xa95bc0) at 0xa95bd0 REFCNT = 1 FLAGS = (ROK) RV = 0xa77998 SV = PV(0xa75c20) at 0xa77998 REFCNT = 1 <--- FLAGS = (POK,pPOK) PV = 0xa8ee40 "a"\0 CUR = 1 LEN = 16

(note the refcounts)

Replies are listed 'Best First'.
Re^3: Update references
by stevieb (Canon) on May 13, 2012 at 21:09 UTC

    That's what I was after, and it makes complete sense. Thanks!