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

为什么Perl发出的没有括号的“使用”转移是不明确的“警告?

发布时间:2020-12-15 21:12:02 所属栏目:大数据 来源:网络整理
导读:有人知道解析或优先级决定是否导致“不使用括号”的“使用”转移是不明确的“,代码如下: shift . 'some string';# and not(shift) . 'some string'; # orshift() . 'some string'; 这是否有意使某些句法结构更容易?还是仅仅是Perl解析器工作的方法呢? 注
有人知道解析或优先级决定是否导致“不使用括号”的“使用”转移是不明确的“,代码如下:
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).

(编辑:李大同)

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

    推荐文章
      热点阅读