开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜