Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How to end a Perl script

by dsb (Chaplain)
on May 02, 2002 at 20:00 UTC ( [id://163657]=note: print w/replies, xml ) Need Help??


in reply to How to end a Perl script

1. 1; # A simple number 1
This notation is commonly used when writing modules. In order to successfully load a module at compile time, that module must return a true value. Having a 1(a valid true value) as the last command in the module ensures that at true value will be returned.

2. exit; # The exit command
I use exit mostly during testing and development. Otherwise I'd rather use another way to bail out of my script if processing is finished. Using exit could be better for all I know, since an exit is sure to do just that.

3. goto BOTTOM; # goto a label at the end of the script
From what I understand goto's can create instability in the scripts. I don't think I've ever seen them used in anything outside of obfu.

4. &footer; # Nothing, just the end of the script
This is the one I most often use, unless I'm working with objects in which case I call the appropriate destructors before letting the program end.
Ex.

$sth->finish(); $dbh->disconnect();




Amel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://163657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-26 03:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found