有人知道解析或优先级决定是否导致“不使用括号”的“使用”转移是不明确的“,代码如下:
shift . 'some string'; # and not (shift) . 'some string'; # or shift() . 'some string';
这是否有意使某些句法结构更容易?还是仅仅是Perl解析器工作的方法呢?
注意:这是关于语言设计的讨论,而不是一个建议的地方
"@{[shift]}some string"
解决方法
使用诊断程序,您将获得有用的信息:
Warning: Use of "shift" without parentheses is ambiguous at (eval 9)[/usr/lib/perl5/5.8/perl5db.pl:628] line 2 (#1) (S ambiguous) You wrote a unary operator followed by something that looks like a binary operator that could also have been interpreted as a term or unary operator. For instance,if you know that the rand function has a default argument of 1.0,and you write rand + 5; you may THINK you wrote the same thing as rand() + 5; but in actual fact,you got rand(+5); So put in parentheses to say what you really mean.
恐惧是你可以写一些像shift.5这样的东西,它将被解析为shift(0.5).