Welcome to the Monastery | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
A reference to the array is stored in the global (package) variable $array_ref (which itself doesn't go out of scope). This increments the reference count of @array, so the array doesn't "vaporize" even though it is scoped lexically to the routine. You can use Devel::Peek to investigate the reference counts. When you add
at the end of A(), and within B(), you'll see that the REFCNT is 2 within A(), but 1 within B()
This is because when @array leaves its scope, the REFCNT is decremented. If there was no reference kept to it, the REFCNT would go down to zero here, and the variable would be freed. But due to the reference, this doesn't happen. In reply to Re: Does Scope of Referenced Array Matter?
by Eliya
|
|