Perl::...ompare(3pm)

πŸ’… NAME πŸ’…

okay bestie, welcome to Perl::Critic::Policy::ValuesAndExpressions::NotWithCompare β€” she's a policy that catches logical not used with compare. That's it, that's the whole vibe. (Also the man page header up top is literally truncated to Perl::...ompare(3pm), πŸ’€, but you found her and that's what matters.)


✨ DESCRIPTION ✨

So this policy lives in the Perl::Critic::Pulp add-on 🫢 and she's here to clock those little moments where you slapped a logical not ! next to a comparison, like:

! $x =~ /^[123]/  # bad
! $x + $y >= $z   # bad

and no, she's not being dramatic β€” because of precedence, Perl is out here parsing those as (!$x), i.e. literally:

(! $x) =~ /^[123]/
(! $x) + $y >= $z

NOT as a negated comparison like you probably meant. 😭 Precedence said "not today." And usually that's just a straight-up mistake, which is why this policy reps the bugs theme (peep "POLICY THEMES" in Perl::Critic for the whole theme situation).

BUT. As a special case πŸ‘‘, ! on both sides of == or != is fully allowed, because honestly that's a pretty great way to compare booleans:

!$x == !$y   # ok
!$x != !$y   # ok

iconic, we love a well-behaved boolean comparison, no notes ✨


🌸 LIMITATIONS 🌸

okay so she's not omniscient (nobody is, she's doing her best πŸ’…). User functions called without parentheses get assumed to be the usual varargs style. But a prototype can mean that's lowkey not the case, which lets a bad !-with-compare expression slip past undetected πŸ™ˆ:

! userfunc $x == 123   # indeterminate
# without prototype would be ok:   ! (userfunc ($x==123))
# with ($) prototype would be bad: (! userfunc($x)) == 123

Now, what she does recognise βœ…: Perl builtins with no args, and constant subs created with use constant or sub FOO () {...} in the file under test. Hopefully anything else too weird is, like, rare, fr fr:

! time == 1   # bad

use constant FIVE => 5;
! FIVE < 1    # bad

sub name () { "foo" }
! name =~ /bar/    # bad

πŸ¦‹ SEE ALSO πŸ¦‹

  • Perl::Critic::Pulp
  • Perl::Critic

🌈 HOME PAGE 🌈

http://user42.tuxfamily.org/perl-critic-pulp/index.html


Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde

Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.


also quick legality check: free software, GPL v3-or-later, no warranty, you def should've gotten a copy of the license with it β€” read the fine print bestie, it's giving ✨responsible✨ 🫢

and that's a wrap!! this page came from perl v5.40.1 on 2025-10-21, so if your version is different, pls go read her version instead πŸ’– bye ily πŸ¦‹

πŸ“¦ where this page comes from