为什么我不能在Perl中打印后立即使用文字列表切片?

前端之家收集整理的这篇文章主要介绍了为什么我不能在Perl中打印后立即使用文字列表切片?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道我可以这样做:

print STDOUT (split /\./,'www.stackoverflow.com')[1];

并打印“stackoverflow”.但是,这个:

print +(split /\./,'www.stackoverflow.com')[1];

做同样的事,这个:

print (split /\./,'www.stackoverflow.com')[1];

是语法错误.那到底是怎么回事?我总是理解一元加号在任何情况下都不做任何事情.如果“print FILEHANDLE EXPR”有效,我会想象“打印EXPR”总能同样有效.任何见解?

解决方法

您没有启用警告.在print(…)[1]的情况下,括号集被视为函数语法的一部分.

print (...) interpreted as function at C:\Temp\t.pl line 4.

从,perldoc -f print

Also be careful not to follow the print keyword with a left parenthesis unless you want the corresponding right parenthesis to terminate the arguments to the print—interpose a + or put parentheses around all the arguments.

另见Why aren’t newlines being printed in this Perl code?

猜你在找的Perl相关文章