如何在 Perl 程序中暂时抑制 STDOUT? [英] How can I suppress STDOUT temporarily in a Perl program?
问题描述
有没有什么简单的方法可以告诉 perl现在忽略打印的所有内容"?
Is there any easy way to tell perl "now ignore everything that is printed"?
我必须在外部 Perl 模块中调用一个过程,但该过程打印了很多不必要的信息(全部通过标准打印).
I have to call a procedure in an external Perl module, but the procedure prints a lot of unnecessary information (all through standard print).
我知道 select 可用于以某种方式重定向它,但我阅读 perldoc 并不太明智.
I know select can be used to redirect it somehow, but I am not too wise from reading perldoc on it.
编辑:我更早找到了答案,但我会添加一个示例以使其更清楚(但我猜的不多)
edit: I found the answer sooner, but I will add an example to make it clearer (but not much I guess)
use TectoMT::Scenario;
use TectoMT::Document;
sub tagDocuments {
my @documents = @_;
my $scenario = TectoMT::Scenario->new({'blocks'=> [ qw(
SCzechW_to_SCzechM::Sentence_segmentation
SCzechW_to_SCzechM::Tokenize
SCzechW_to_SCzechM::TagHajic
SCzechM_to_SCzechN::Czech_named_ent_SVM_recognizer) ]});
$scenario->apply_on_tmt_documents(@documents);
return @documents;
}
TectoMT::Scenario 和 TectoMT::Document 是外部模块
TectoMT::Scenario and TectoMT::Document are those external modules
推荐答案
我自己的答案:
use IO::Null;
print "does print.";
my $null = IO::Null;
my $oldfh = select($null);
print "does not print.";
select($oldfh);
print "does print.";
这篇关于如何在 Perl 程序中暂时抑制 STDOUT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!