"be consistent" | |
PerlMonks |
'xor' operator is not a sibling to 'or' and 'and'?by rsFalse (Chaplain) |
on Dec 18, 2019 at 20:29 UTC ( [id://11110345]=perlquestion: print w/replies, xml ) | Need Help?? |
rsFalse has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I have used 'xor' operator as lower precedence comma, because I understood a logic that it cannot short-circuit as do 'or' and 'and', and the last expression must be evaluated at the end. E.g. I used 'xor' in short sentences like this, to avoid unnecessary parentheses: Output: Today I found (for myself) that 'xor' doesn't work in the same way as 'or' and 'and' do, and it is strange for me, why. It seems that, 'xor' not only evaluates one or both expressions surrounding it, but also evaluates logical XOR of these expressions, when 'or' and 'and' operators don't do this, i.e.: Output: At the last line of output I expected to get '3'! I could get '3' by using a comma instead (and forcing scalar context): 'scalar( 2, 3 ),'. I'm not sure this difference of behaviour of operators is written somewhere in documentation, but I haven't find it in 'perlop'.
Back to
Seekers of Perl Wisdom
|
|