为什么打印(@ARGV),"\n"不打印Perl中的换行符?

dev*_*ium 0 perl

是什么原因

print (@ARGV), "\n";
Run Code Online (Sandbox Code Playgroud)

不打印结束换行符但是

print @ARGV, "\n";
Run Code Online (Sandbox Code Playgroud)

呢?在这种情况下,我假设括号是中性的?或者即使他们正在捣乱,@ARGV为什么他们还会打印新线?

谢谢

ike*_*ami 8

$ perl -we'print (@ARGV), "\n";'
print (...) interpreted as function at -e line 1.
Useless use of a constant (
) in void context at -e line 1.
Run Code Online (Sandbox Code Playgroud)

两者之间没有区别

print (@ARGV), "\n";
Run Code Online (Sandbox Code Playgroud)

print(@ARGV), "\n";
Run Code Online (Sandbox Code Playgroud)

所以你正在做

print(@ARGV); "\n";
Run Code Online (Sandbox Code Playgroud)

解决方案:

print +(@ARGV), "\n";
print @ARGV, "\n";
print((@ARGV), "\n");
print(@ARGV, "\n");
...
Run Code Online (Sandbox Code Playgroud)


yst*_*sth 5

圆括号永远不会在perl中出现.他们只确定优先权和synxtax.

print()是一个子程序调用,传递括号中的内容进行打印.即使前面有空间.当你在括号前有空格时,这可能不是你想要的,所以perl会警告你......如果你启用了警告.它还会警告你"\n"是没用的,因为它处于无效的上下文中.

$ perl -we'print (@ARGV), "\n"'
print (...) interpreted as function at -e line 1.
Useless use of a constant ("\n") in void context at -e line 1.
Run Code Online (Sandbox Code Playgroud)