以编程方式从STDIN或Perl中的输入文件中读取 [英] Programmatically read from STDIN or input file in Perl
本文介绍了以编程方式从STDIN或Perl中的输入文件中读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Perl中以编程方式从stdin或输入文件(如果提供)中读取的最巧妙的方法是什么?
What is the slickest way to programatically read from stdin or an input file (if provided) in Perl?
推荐答案
while (<>) {
print;
}
将从命令行上指定的文件中读取,或者如果未提供文件,则从stdin中读取
will read either from a file specified on the command line or from stdin if no file is given
If you are required this loop construction in command line, then you may use -n
option:
$ perl -ne 'print;'
在这里,您只需将代码从第一个示例的{}
放入第二个的''
Here you just put code between {}
from first example into ''
in second
这篇关于以编程方式从STDIN或Perl中的输入文件中读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文