Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How to end a Perl script

by dws (Chancellor)
on May 02, 2002 at 21:23 UTC ( [id://163670]=note: print w/replies, xml ) Need Help??


in reply to How to end a Perl script

I've seen Perl scripts end in numerous ways, ...

For completeness, add     die "$file: $!";    # for example which exits unless caught by a __DIE__ handler.

I rarely embed an exit(), favoring die() instead.

Replies are listed 'Best First'.
Re x 2: How to end a Perl script
by Sweeper (Pilgrim) on May 03, 2002 at 05:21 UTC
    I rarely embed an exit(), favoring die() instead.

    The purpose of die is to report an error to the calling program, and the exit code is not zero. Using die when everything went right in your Perl program may trigger unexpected behaviour in your calling program. Imagine for instance using your program in a makefile. The make process would end immediately, and you would not know why.

      Using die when everything went right in your Perl program may trigger unexpected behaviour in your calling program.

      If I exit from within a script (as opposed to falling off the end), then something went wrong, and die() is the right thing to do. Using exit() from anywhere down the call stack is kind of like using a goto. I try not to do it. Using a die() from within an eval block is different, since that's the equivalent of throwing an exception.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-19 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found