Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将相同的文本输出到两个不同的文件(这是我正在测试的应用程序要求)。现在,我不想打开两个文件句柄,每个写两行,然后在我的代码中关闭它们十几次。
有没有一种简单的方法,可能在 Perl 中使用一行(但不是在 CLI 中!),将相同的文本发送到两个不同的文件?
使用IO::Tee。
从文档的示例中:
use IO::Tee; $tee = IO::Tee->new($handle1, $handle2); print $tee "foo", "bar";