How do I dump a stacktrace (Carp output) to a file in Perl?
I want to dump the output of Carp to a file handle in perl, instead of to stderr.
The file handle is already open.
What is the easiest way to do this?
exampl开发者_StackOverflow中文版e:
use strict;
use warnings;
use FileHandle;
use Carp;
my $fh = new FileHandle("log", "w") || croak "could not write 'log'";
# stuff happens
print $fh carp("stack trace");
close($fh);
The example will print "1" to the log, because that is the return value of carp.
print $fh "stack trace";
print $fh Carp::longmess();
精彩评论