微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么我不能在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?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐