Perl - 抑制控制台输出?

Jer*_*emy 3 console perl

我想用一种原生方式来解决这个问题......

我有一个perl命令,可以进行调用,有时会直接将文本打印到控制台.

我想要这样的东西:

$text = get_output_from(MagicCommandICan'tChange());
if ($text neq "a specific value") {
  print $text;
}
Run Code Online (Sandbox Code Playgroud)

有什么办法吗?

Dan*_*mer 7

看到 IO::CaptureOutput

 use IO::CaptureOutput qw(capture qxx qxy);

 # STDOUT and STDERR separately
 capture { noisy_sub(@args) } \$stdout, \$stderr;
Run Code Online (Sandbox Code Playgroud)