@H_404_2@
这里发生了什么?为什么不是$c == 1?
$cat y.pl #!/usr/bin/perl $a = 0; $b = 1; $c = $a xor $b; print "$a ^ $b = $c\n"; $./y.pl 0 ^ 1 = 0
解决方法
一直用
use strict; use warnings qw( all );
它会检测到您的优先问题.
Useless use of logical xor in void context
特别,
$c = $a xor $b;
手段
($c = $a) xor $b;
运算符和,或者,而不是和xor的优先级非常低.这对流量控制起作用,或者对流量控制非常有用.
... or die ...; ... or next;
xor不会短路,因此对流量控制没有用. xor是出于完全不同的原因而创建的.喜欢或者,xor是一个逻辑运算符.这意味着将整个操作数的真实性视为整体而不是逐位比较.我不相信这是你想要的操作.
固定:
$c = $a ^ $b;
Low Precedence Operation Bitwise Logical Logical ---------- ---------- ---------- ---------- NOT ~ ! not AND & && and OR | || or OR* N/A // N/A XOR ^ N/A xor OR* - Like OR,but only undefined is considered false.
@H_404_2@