in reply to Re: Re: Scope of Hash variable
in thread Scope of Hash variable
In this example, $variable will disappear when you leave that subroutine. The memory will not be free'd in that your process's memory usage will decrease, but the memory it was using is now available to be claimed by other variables in your code.sub my_sub { my $variable; ... } # or if ($some_condition) { my $other_variable; ... } # $other_variable disappears when 'if' block exits!
Generally Perl's garbage collection is meant to keep the tasks of memory management away from you, so you don't have to worry about it. So long as you use strict, Perl will just about force you to declare your variables, which means you have the opportunity to scope them where they are appropriate, and let them disappear when you're done with them. You may wish to get your hands on some Perl books that talks about this in more detail, and I think it's been covered on the site a few times, so a Super Search may give you some more help.
Hope this answers your question..
|
|---|