我知道我可以这样做:
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.
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.