Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Do you know where your variables are?
 
PerlMonks  

Re: How aggressively does Perl clean up when you exit()?

by Aristotle (Chancellor)
on Nov 14, 2001 at 20:26 UTC ( [id://125425]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to How aggressively does Perl clean up when you exit()?

There is a fine difference to note here.

On the one hand you have the "standard" resources - memory, file handles and the like; these resources are provided by the interpreter as it executes your script. These resources are also guaranteed to be cleaned up on exit() (so long as you're not dumping core or something).

Then there's "external" resources the code in execution may have allocated - like, a database driver may have asked the database to allocate a handle. These resources will not be released automatically, rather, the code in question has to make sure they are returned. In case you're using CPAN modules, it is safe to assume that, bugs aside, all of them clean up behind themselves.

As has been mentioned, you may want to look into what END { } and DESTROY { } do: define a blocks of code that will always be executed the end of the program or when the corresponding object goes out of scope, respectively. This is (almost) regardless of how you fall out (of the program or scope). Properly written modules (such as the ones available on CPAN :)) use these to make sure they neatly clean up after themselves.

Long reply, short point: yes. You can use exit() to fall out of your scripts at whichever point you choose.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://125425]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.