我想将Carp的输出转储到perl中的文件句柄,而不是stderr.
文件句柄已经打开.
最简单的方法是什么?
例:
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);
Run Code Online (Sandbox Code Playgroud)
该示例将向日志打印"1",因为这是carp的返回值.
print $fh "stack trace";
print $fh Carp::longmess();
Run Code Online (Sandbox Code Playgroud)