为什么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).

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...