Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: 'xor' operator is not a sibling to 'or' and 'and'?

by Fletch (Bishop)
on Dec 18, 2019 at 21:04 UTC ( [id://11110352]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11110352]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found