Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

I'll defer to ikegami's (amended) reply for the differences between those two items. For completeness, I'll also mention another more rarely used option and explain their relative usefulness.

One may also wish to compare and contrast POSIX::_exit which exits the program immediately. It does not run destructors or END blocks and doesn't flush buffered I/O streams. Both die and exit do those things before they cause the program to exit to the OS.

The behavior usually wanted is that of die(). You might not be catching the condition now, but you may want to later.

Sometimes exit() is preferred. You might want to exit in a way that specifically always exits the program and ends the process. You might want to write your error condition somewhere other than STDERR then return a specific error code to the parent program. I've written some network server code that uses print() and exit() to do just that.

Only quite rarely will POSIX::_exit() be needed. Most people will probably never find a good reason to use it, but it's available in case it is needed.

In reply to Re: different between die and exit by mr_mischief
in thread different between die and exit by vinoth.ree

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.