Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Does undef free ram?

by bronto (Priest)
on Jul 17, 2002 at 12:05 UTC ( #182395=note: print w/replies, xml ) Need Help??

in reply to Does undef free ram?

When I need to allocate variables for a limited time, for example when I need them in just a snippet of code, I usually prefer blocks and lexicals instead of undefing. For example:

{ my @needed_here = get_array() ; # do something with data, e.g. coffee(@needed_here) ; } # you are no more @needed_here ;-)

As soon as you get out of the block, @needed_here "disappears" (unless you saved some reference to it, for example in a closure)

I prefer this way instead of undefing because it looks clearer to me --when I need the variable, it's there, when I need it no more it goes away (instead of staying around undefined).

If you are interested in this approach, you could take a look at "Private Variables via my()" in perlsub


# Another Perl edition of a song:
# The End, by The Beatles
  $you->take($love) eq $you->made($love) ;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://182395]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2017-12-12 07:00 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (326 votes). Check out past polls.