Logical XOR
Logical XOR
Posted Jun 10, 2024 16:08 UTC (Mon) by rweikusat2 (subscriber, #117920)Parent article: perl v5.40.0 released
Posted Jun 10, 2024 16:38 UTC (Mon)
by proski (subscriber, #104)
[Link]
Posted Jun 10, 2024 16:53 UTC (Mon)
by jccleaver (guest, #127418)
[Link] (7 responses)
Posted Jun 10, 2024 17:19 UTC (Mon)
by pbonzini (subscriber, #60935)
[Link] (6 responses)
Posted Jun 10, 2024 18:20 UTC (Mon)
by smurf (subscriber, #17840)
[Link] (3 responses)
On the other hand, I haven't programmed anything Perl-ish for the last 15 years, so what do I know?
Posted Jun 10, 2024 19:33 UTC (Mon)
by mathstuf (subscriber, #69389)
[Link]
Posted Jun 10, 2024 20:21 UTC (Mon)
by rweikusat2 (subscriber, #117920)
[Link] (1 responses)
0 != "a"
is false but
!0 != !"a"
is true.
Posted Jun 11, 2024 19:22 UTC (Tue)
by jwilk (subscriber, #63328)
[Link]
Since v5.36, it kinda has:
https://perldoc.perl.org/perl5360delta#Stable-boolean-tra...
Posted Jun 10, 2024 18:25 UTC (Mon)
by rweikusat2 (subscriber, #117920)
[Link]
perl -e '$a = 0; $b = 'abc'; print(($a || $b) && !($a && $b) && ($a == $b), "\n")'
:-)
Posted Jun 11, 2024 22:58 UTC (Tue)
by MarcB (guest, #101804)
[Link]
That is all this change is about. Now all logical operator exist in three versions: bit-wise, high-precedence logical and low-precedence logical.
See https://perldoc.perl.org/perlop#Operator-Precedence-and-A...
Posted Jun 10, 2024 17:04 UTC (Mon)
by mb (subscriber, #50428)
[Link]
Well, that's easy.
¯\_(ツ)_/¯
Posted Jun 10, 2024 19:22 UTC (Mon)
by sub2LWN (subscriber, #134200)
[Link] (7 responses)
Posted Jun 10, 2024 21:18 UTC (Mon)
by dskoll (subscriber, #1630)
[Link] (6 responses)
Oof, C does not have a logical XOR, so calling it "C-style" is a bit of a stretch. I can't recall ever needing a logical XOR, but if I did, I would be perfectly fine with writing I suppose if A and B had side-effects, that might be a problem, but just Don't Do That.
Posted Jun 11, 2024 4:20 UTC (Tue)
by willy (subscriber, #9762)
[Link] (5 responses)
Posted Jun 11, 2024 16:37 UTC (Tue)
by dskoll (subscriber, #1630)
[Link] (4 responses)
Yup, xor is not often used in general-purpose software, though it is used in quite a few encryption and hashing algorithms. But that's bitwise-xor. I'm scratching my head trying to come up with a scenario where logical-xor is needed. I agree that reserving ^ for exponentiation would have been better than reserving it for xor, but that's water under the bridge.
Posted Jun 11, 2024 17:52 UTC (Tue)
by NYKevin (subscriber, #129325)
[Link]
Posted Jun 11, 2024 23:04 UTC (Tue)
by MarcB (guest, #101804)
[Link]
Posted Jun 14, 2024 15:57 UTC (Fri)
by magnus (subscriber, #34778)
[Link] (1 responses)
Posted Jun 14, 2024 16:48 UTC (Fri)
by atnot (subscriber, #124910)
[Link]
Logical XOR
Logical XOR
Logical XOR
Logical XOR
Logical XOR
Logical XOR
Logical XOR
Logical XOR
Logical XOR
Logical XOR
If you think coding is fun, use ^^
C-Style Logical XOR
C-Style Logical XOR
(A && !B) || (B && !A)
. And yes, I know the parens are not strictly necessary, but I like them.
C-Style Logical XOR
C-Style Logical XOR
C-Style Logical XOR
C-Style Logical XOR
C-Style Logical XOR
C-Style Logical XOR