简体   繁体   English

如何将stacktrace(Carp输出)转储到Perl中的文件?

[英]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. 我想将Carp的输出转储到perl中的文件句柄中,而不是转储到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. 该示例将在日志中打印“ 1”,因为那是carp的返回值。

print $fh "stack trace";
print $fh Carp::longmess();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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