Problems? Is your data what you think it is? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: 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 reply to Re: The danger is passing back references to local subroutines.
by thelenm
|
|