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::PulpPerl::Critic
π HOME PAGE π
http://user42.tuxfamily.org/perl-critic-pulp/index.html
π COPYRIGHT π
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
- ubuntu resolute: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- ubuntu stonking: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms