这个问题在这里已经有了答案:
Perl: Print on the "display" and also into a file
(4 个回答)
8年前关闭。
我有一个带有几个打印语句的 Perl 脚本。有没有一种方法可以将所有这些打印语句同时定向到文件和标准输出而不复制打印语句?
最佳答案
您可以使用 File::Tee .
use File::Tee qw(tee);
tee STDOUT, '>>', 'some_file.out';
print "w00p w00p";
如
File::Tee
不可用,它很容易用管道模拟:open my $tee, "|-", "tee some_file.out";
print $tee "w00p w00p";
close $tee;
关于perl - 同时打印到标准输出和文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16652836/