Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
#的作用是什么!usr/bin/perl-n?_Perl - Fatal编程技术网

#的作用是什么!usr/bin/perl-n?

#的作用是什么!usr/bin/perl-n?,perl,Perl,#的角色是什么!usr/bin/perl-n?我试图参考书籍和其他来源,但我没有得到更好的想法。它的行为类似于STDIN,例如my@array=许多输入被存储到@array中-n的行为也与此类似,但如何将输入值存储在数据类型中。?哪一个是原始函数 它本质上为您提供了包装您在命令行中放置的内容的管道: while (<>) { ... What you have on cmd line here ... } 是等效的。使用-n选项,脚本中的代码将被解释为您编写了以下代码: whil

#的角色是什么!usr/bin/perl-n
?我试图参考书籍和其他来源,但我没有得到更好的想法。它的行为类似于STDIN,例如
my@array=
许多输入被存储到
@array
-n
的行为也与此类似,但如何将输入值存储在数据类型中。?哪一个是原始函数

它本质上为您提供了包装您在命令行中放置的内容的管道:

while (<>) {  ... What you have on cmd line here ... }

是等效的。

使用-n选项,脚本中的代码将被解释为您编写了以下代码:

while (<>) {
   <code>
}
例如,以下以文件作为参数调用的脚本将替换文件的所有行尾,并在标准输出上发送结果:

#!usr/bin/perl -n
~s/\n//;
print ; 
必须这样称呼它:

perl script.pl <file>
perlscript.pl

看看perlrun之前的命令开关部分,我将执行
perl-h
。这通常就足够了。
#!usr/bin/perl -n
~s/\n//;
print ; 
perl script.pl <file>