thejerryman has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone, Where does the die command print its output. Can I "reroute" it to print to STDERR or some other arbitrary file? Thanks EDIT - I found out how to do it: open STDERR, ">filename.txt"; That "reroutes" STDERR to the file. Thanks anyways

Replies are listed 'Best First'.
Re: STDERR and die
by lakshmananindia (Chaplain) on Jan 16, 2009 at 11:57 UTC

    If you want to print the error in some other file then, use $SIG{__DIE__} handler. Inside that handler log the message in the file that you want to store the message.

      You can simply use open function like below:
      open (STDERR, ">>err.log") or die "can't redirect STDERR $!\n";
      But you might find something turning your eyes on if you search CPAN before writing this code.


      I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Re: STDERR and die
by Corion (Patriarch) on Jan 16, 2009 at 11:49 UTC

    The documentation for the 'die' function says the following:

    Outside an eval, prints the value of LIST to STDERR and exits with the current value of $! (errno). If $! is 0 , exits with the value of ($?>> 8) (backtick `command` status).

    Maybe you can help us to improve the Perl documentation by suggesting a change that would have made the answer to your question clearer to you when you read the documentation.