gpt4 book ai didi

perl - 同时打印到标准输出和文件

转载 作者:行者123 更新时间:2023-12-04 11:39:53 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com