我正在使用Test :: More编写一些测试,并且我正在测试的一个函数打印到STDERR.我想测试输出到STDERR,但有点不确定如何做到这一点.我知道我很亲密.这有效:
@H_403_2@use strict;
use warnings;
use feature qw(say);
close STDERR;
open STDERR,">",\my $error_string;
say STDERR "This is my message";
say qq(The \$error_string is equal to "$error_string");
打印出:
@H_403_2@The $error_string is equal to "This is my message "但是,我不想关闭STDERR.我只是想重复它.
我试过这个:
@H_403_2@use strict; use warnings; use feature qw(say); open my $error_fh,my $error_string; open STDERR,">&",$error_fh; say STDERR "This is my message"; close $error_fh; say qq(The \$error_string is equal to "$error_string");但是,$error_string是空白的.
我究竟做错了什么?