有什么方法可以同时打印到“显示器”和文件中,而不必重复打印“字符串”代码?Perl:在“显示器”上打印,也打印到文件中
我想做什么:的
if ($ofile) {
open (FILE, '>>', "file");
print "Hello" #some code#; #prints on the display and into the file
}
代替:
if ($ofile) { open (FILE, '>>', "file"); }
print "Hello";
if ($ofile) { print FILE "Hello"; }
试着用搜索引擎,但所有我发现要么,或者不是两个特征组合在一起。
编辑补充问题:
然后使用IO :: T恤,以创建一个新的tee'd处理,然后选择$ T恤,使打印默认使用它。 - 埃里克斯特罗姆
@EricStrom你是什么意思创建一个新的tee'd句柄?你的意思是Local::TeeOutput
? search.cpan.org/~mschilli/Log-Log4perl-1.34/lib/Log/Log4perl.pm
@EricStrom你有个例子吗?
@EricStrom Local :: TeeOutput在Strawberry Perl的默认库中不可用。有没有其他的选择在默认库里面?
这个api是否必须安装或者是否预安装了Strawberry Perl? – 2011-12-23 19:33:22
@ parapura-rajikumar我只需要打印出一些东西。我是否使用Log4perl的print_portfolio子功能? – 2011-12-23 19:43:48
@JohnTan请看我的编辑回答。我有一个完整的例子。如果你的perl安装还没有安装,你将不得不安装Log4perl。一旦你掌握了它的一切你将停止所有打印:) – 2011-12-24 17:00:11