为什么Perl发出的"使用"转移"没有括号"是一个含糊不清的警告?

Eri*_*rom 12 syntax perl warnings

有没有人知道什么解析或优先级决定导致警告'使用'shift"没有括号是不明确的'为代码发出,如:

shift . 'some string';

# and not

(shift) . 'some string'; # or
shift() . 'some string';
Run Code Online (Sandbox Code Playgroud)

这是否有意使某些句法结构更容易?或者它只是perl解析器工作方式的工件?

注意:这是关于语言设计的讨论,而不是建议的地方

"@{[shift]}some string"
Run Code Online (Sandbox Code Playgroud)

mob*_*mob 27

有了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).


yst*_*sth 8

对于解析器已经确定,不明确并不意味着真正含糊不清,只是含糊不清. shift .特别是"模糊",因为.可以启动一个术语(例如.123)或一个运算符,因此它不足以确定后面的是shift的操作数或者shift()是操作数的运算符(并且解析器不是'聪明到足以知道:a). 不是这个术语的开头或b).123不是转换的有效操作数.