为什么 perl 中 // 的优先级低于 equal 的优先级?
为什么在(至少)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;
(对我来说)打印出非常意想不到的结果。
Why does //
have lower precedence than ==
in (at least) perl 5.010?
For example, this
use 5.010;
my $may_be_undefined = 1;
my $is_equal_to_two = ($may_be_undefined//0 == 2);
say $is_equal_to_two;
prints (for me) very unexpected result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
//
以及==
所属的运算符类别。==
是一个“相等运算符”,尽管//
属于“C 风格逻辑运算符”类别”。举个例子;
&&
与//
属于同一“类别”,也就是说,下面的两个语句在涉及到时是等效的运算符优先级。这样可能更容易理解吧?C 风格逻辑定义或的文档 ( // )
运算符优先级和关联性的文档
It's because of the category of operators which
//
falls under, aswell as==
.==
is an "equality operator" though//
falls under the category of "C-style logical operators".As an example;
&&
is in the same "category" as//
, with that said both of the statements below are equivalent when it comes to operator precedence. That might make it easier to understand?Documentation of C-style Logical Defined-Or ( // )
Documentation of Operator Precedence and Associativity