Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: The danger is passing back references to local subroutines.by thelenm (Vicar) |
on Jun 18, 2002 at 19:40 UTC ( [id://175475]=note: print w/replies, xml ) | Need Help?? |
Perl variables are reference-counted, and are automatically destroyed when the reference count reaches zero. Since your subroutine is returning a reference to a scalar, that scalar will not automatically be destroyed when the subroutine exits. That's because there's still a reference to it, as long as you store that reference somewhere. If you get rid of that reference (i.e., the variable where you stored the reference goes out of scope or is undefed), then the data will be destroyed.
Update: I forgot to give a helpful reference: perlref and perlobj have some nice information on reference counting if you want to know more. -- Mike --
In Section
Seekers of Perl Wisdom
|
|