随着use diagnostics
,你得到的有用信息:
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)
。
来源
2009-10-18 05:32:42
mob
我会赞成,但“我的每日投票限制已达到。”我认为那是一个错误,因为我认为SO应该在重置的时候下降几分钟,所以我因为昨天投了票而受到惩罚。 – 2009-10-18 05:34:31
在rand(; $)的情况下,我可以看到警告的情况,但是,由于shift的原型(; \ @)似乎并不存在,因此shift的原型(; \ @)会阻止字符串或数字成为有效参数 – 2009-10-18 17:19:40
@Eric Strom:这个错误来自标记器,这不是那么聪明。无关地,移位的原型并不是真的(; \ @),因为这会使它成为一个列表操作符,而实际上它是一个一元操作符。 – ysth 2009-10-18 17:57:26