Think about Loose Coupling | |
PerlMonks |
Re: Do subroutine variables get destroyed?by Tanktalus (Canon) |
on May 08, 2016 at 04:50 UTC ( [id://1162460]=note: print w/replies, xml ) | Need Help?? |
Everything in perl is on the heap (*). Variables are created when necessary (my variables are created when the my statement executes), and cleaned up as soon as there are no references left to them. This allows you to create new hashes, arrays, etc., in your sub, and then return references to them and have them still work. Compared to C, this is basically perl calling malloc for you for each variable declaration, and then calling free automatically not when the variable goes out of scope, but when there are no more references to that variable. (*) Not quite true. But close enough for our purposes.
In Section
Seekers of Perl Wisdom
|
|