加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 06:11:39 所属栏目:大数据 来源:网络整理
导读:我知道我可以这样做: print STDOUT (split /./,'www.stackoverflow.com')[1]; 并打
我知道我可以这样做:

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:Tempt.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?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读