简体   繁体   中英

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?

example:

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM