title: How can I redirect output of die function to a file in Perl?
body: <p>I want to redirect the <code>die</code> messages to a separate file so that I can compare that file later to determine what went wrong.</p>
  
  <p>But this code gives me errors:</p>
  
  <pre><code>$ cat test.pl
  use strict;
  use warnings;
  
  my $log = "msglog.log";
  die $log "DEAD$!";
  
  $ perl test.pl
  Missing comma after first argument to die function at test.pl line 5, near ""DEAD$!";"
  Execution of test.pl aborted due to compilation errors.
  $ 
  </code></pre>
  
  <p>I do not want to do a <code>2&gt;</code> from the caller. Is there someway to redirect them from within the script?</p>