From 55a059e991160a536905db9f04d215831a4646c9 Mon Sep 17 00:00:00 2001 From: Lukas Mai Date: Thu, 19 Sep 2024 00:19:56 +0200 Subject: [PATCH] perldelta for 570fa433 (`!$x == $y` warning) --- pod/perldelta.pod | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 263d6a69cace..ad60c3349fa9 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -208,6 +208,47 @@ XXX L XXX L +=item * + +L + +(W precedence) You wrote something like + + !$x < $y # parsed as: (!$x) < $y + !$x eq $y # parsed as: (!$x) eq $y + !$x =~ /regex/ # parsed as: (!$x) =~ /regex/ + !$obj isa Some::Class # parsed as: (!$obj) isa Some::Class + +but because C has higher precedence than comparison operators, C<=~>, and +C, this is interpreted as comparing/matching the logical negation of the +first operand, instead of negating the result of the comparison/match. + +To disambiguate, either use a negated comparison/binding operator: + + $x >= $y + $x ne $y + $x !~ /regex/ + +... or parentheses: + + !($x < $y) + !($x eq $y) + !($x =~ /regex/) + !($obj isa Some::Class) + +... or the low-precedence C operator: + + not $x < $y + not $x eq $y + not $x =~ /regex/ + not $obj isa Some::Class + +(If you did mean to compare the boolean result of negating the first operand, +parenthesize as C<< (!$x) < $y >>, C<< (!$x) eq $y >>, etc.) + +(This warning subsumes the C +warning from the previous perl release.) + =back =head2 Changes to Existing Diagnostics