in reply to Re^2: 'xor' operator is not a sibling to 'or' and 'and'?
in thread 'xor' operator is not a sibling to 'or' and 'and'?

and and or return the last expression evaluated; xor always evaluates both sides and then returns the exclusive or of those two expressions (not either of the surrounding expressions) so it's always going to be a boolean value either 1 or ''/0. See perlop

Update: On further reflection I think I see what your expectations for the behavior might be based on and/or's behavior: if A xor B is true return whichever of A or B was true, otherwise return false.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^4: 'xor' operator is not a sibling to 'or' and 'and'?
by rsFalse (Chaplain) on Dec 18, 2019 at 21:11 UTC
    In perlop I find that 'Binary "and" returns the logical conjunction of the two surrounding expressions.', not 'the last expression evaluated'. So maybe I misinterpret here? Or maybe text of docs here needs to be improved.

      It's further down under the heading "Logical Defined-Or" (so yes, it's disjoint from the other discussion of && above it):

      The "||", "//" and "&&" operators return the last value evaluated +(unlike C's "||" and "&&", which return 0 or 1). Thus, a reasonably portab +le way to find out the home directory might be:

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Hm, paragraphs about '||,//,&&' and about 'and/or/xor' are distant in docs, because their precedence differs. But also sentences about return values of 'and' and 'or' seems to be incorrect. I think that section needs to be slightly rewritten, with emphasis that 'and' and 'or' do not return logical result, but return evaluated expressions.