为什么//在perl中的优先级低于相等性?
为什么//的优先级低于(至少)perl 5.010的==?
例如,这个 use 5.010; my $may_be_undefined = 1; my $is_equal_to_two = ($may_be_undefined//0 == 2); say $is_equal_to_two; 打印(对我来说)非常意外的结果. 解决方法
这是因为//属于操作符的类别,以及==.
==是一个“平等运算符”,但//属于“C风格的逻辑运算符”类别. 举个例子; &安培;&安培;与//相同的“类别”,其中表示当涉及运算符优先级时,下面的两个语句都是等价的.这可能会让人更容易理解? print "hello world" if $may_be_undefined && 0 == 2; print "hello world" if $may_be_undefined // 0 == 2; Documentation of C-style Logical Defined-Or ( // )
Documentation of Operator Precedence and Associativity (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |