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:
#!/usr/bin/perl -l use strict; use warnings; push @_, $_ xor print $_ for 'a' .. 'b'; print @_;
Output:
Useless use of logical xor in void context at ./perlmonks_xor_vs_or_an +d.pl line 6. a b ab
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.:
#!/usr/bin/perl -l use strict; use warnings; print "[$_]" for ( 2 and 3 ), ( 2 or 3 ), ( 2 xor 3 ), ;
Output:
[3] [2] []
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'.

In reply to 'xor' operator is not a sibling to 'or' and 'and'? by rsFalse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.