|
|
Subscribe / Log in / New account

Logical XOR

Logical XOR

Posted Jun 10, 2024 18:20 UTC (Mon) by smurf (subscriber, #17840)
In reply to: Logical XOR by pbonzini
Parent article: perl v5.40.0 released

Comparison isn't sufficient, you also need to bool-ize one or both values. The Perl-ish way of writing "x xor y" was "!x != !y" which is … meh.

On the other hand, I haven't programmed anything Perl-ish for the last 15 years, so what do I know?


to post comments

Logical XOR

Posted Jun 10, 2024 19:33 UTC (Mon) by mathstuf (subscriber, #69389) [Link]

Why not learn something from Haskell and make it applicative so you can say something like `!*(x = y)` that applies the `!` operator to each token in the inside of the parenthesized expression? Of course, being Perl, maybe this will be adopted too ;) . Or it already has meaning?

Logical XOR

Posted Jun 10, 2024 20:21 UTC (Mon) by rweikusat2 (subscriber, #117920) [Link] (1 responses)

Bool-ize is a bit of a misnomer as Perl has no boolean data type. The value has to be normalized to something where a numerical comparison (!=) works as intended because non-numerical strings are autoconverted to the integer 0 when used in an numerical comparison. In Perl, this expression

0 != "a"

is false but

!0 != !"a"

is true.

Logical XOR

Posted Jun 11, 2024 19:22 UTC (Tue) by jwilk (subscriber, #63328) [Link]

> Perl has no boolean data type

Since v5.36, it kinda has:

https://perldoc.perl.org/perl5360delta#Stable-boolean-tra...


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds