in reply to Re^3: Meaning of this Filehandle Error?
in thread Meaning of this Filehandle Error?

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.