Yeah, no problem, but my point was really that die is really used for exiting a program on an irrecoverable error condition and is therefore designed to provide you additional information on where in the code the program failed, and what line was last read in the last input file handle read if any (because it happens quite often that a program fails upon reading an input line that does not fit the expected pattern or format). BTW, die prints to STDERR, not to STDOUT, even though you don't necessarily the difference if you haven't redirected output.

The exit function, on the other hand, makes it possible to exit the program gracefully, with no error message. To tell the truth, I do not use it very commonly, because my programs usually exit naturally upon completion, but it sometimes happens that you just want to exit early (for example if you figure out that the situation you are examining is OK and that running the program is in the current case useless.

Having said that, the exit function may take a parameter, which will give some information to the operating system on whether the program was successful or not. At least under Unix or Linux, exiting with a 0 value usually indicates successful completion, whereas any other value usually indicates an error (but that's just a common convention, you could do it the other way around if you wished, although I would not recommend to do that, it would make things rather obscure and somewhat obfuscated). This enables the calling script (say a shell script) to figure out whether the program was successful and take appropriate actions depending on that.


In reply to Re^4: Meaning of this Filehandle Error? by Laurent_R
in thread Meaning of this Filehandle Error? by mmartin

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.