Perl::...foreLt(3pm)

πŸ’… NAME πŸ’…

okay bestie, welcome to Perl::Critic::Policy::ValuesAndExpressions::ConstantBeforeLt β€” it lives in the User Contributed Perl Documentation, it's part of the Perl::Critic::Pulp add-on, and honestly? its whole job is so specific. it disallows a bareword right before a <. that's it. that's the girl. πŸŽ€


✨ DESCRIPTION ✨

so this policy is part of the Perl::Critic::Pulp add-on, and what it does is it prohibits a bareword sitting in front of a <, because that is exactly the kind of situation that will drag you into drama with autoloaded or unprototyped constant subs. why?? because when a sub is autoloaded or unprototyped, perl looks at that < and goes "oh! this is a <..> glob or a readline!" instead of a less-than. the audacity, fr. 😭

this policy is filed under the "bugs" theme (peep "POLICY THEMES" in Perl::Critic if you wanna know more).

use POSIX;
DBL_MANT_DIG < 32   # bad, perl 5.8 thinks <>

func <*.c>          # ok, actual glob
time < 2e9          # ok, builtins parse ok

use constant FOO => 16;
FOO < 32            # ok, your own const

sub BAR () { 64 }
BAR < 32            # ok, your own prototyped sub

ok so how do you fix something like DBL_MANT_DIG < 10? 🫢 you parenthesise it β€” either wrapped around, or tacked on after. like:

(DBL_MANT_DIG) < 10  # ok
DBL_MANT_DIG() < 10  # ok

whichever one you personally think is less cursed, girl, that's a you decision. the second one lowkey slaps though, because it's giving "hello, this is really a sub" energy. πŸ‘‘

here's the tea: the whole question is whether the constant sub in question is defined and has a prototype at the moment the code gets compiled. and ConstantBeforeLt makes the pessimistic assumption β€” that anything other than use constant and prototyped subs in your own file should not be relied upon. periodt.

in practice, the problems you're most likely to actually hit are with the POSIX module constants of Perl 5.8.x and earlier, because those were unprototyped. also, the default code generated by h2xs (as of Perl 5.10.0) is the same deal β€” similar autoloaded unprototyped constants β€” so any module using the bare output of that is suffering right along with them. πŸ˜”

now, if you're confident the modules you use don't play tricks with their constants (including only using POSIX on Perl 5.10.0 or higher), then you might find ConstantBeforeLt a little too pessimistic for your taste. ngl it normally triggers pretty rarely anyway. but you can always just disable it altogether in your .perlcriticrc file β€” see "CONFIGURATION" in Perl::Critic:

[-ValuesAndExpressions::ConstantBeforeLt]

🌸 OTHER NOTES 🌸

bareword file handles might get misinterpreted by this policy as constants, πŸ™ˆ but in practice < doesn't really get used with anything that takes a bare filehandle, so like… whatever.

a constant used before it's defined, like this:

if (FOO < 123) { ... }   # bad
...
use constant FOO => 456;

gets reported by ConstantBeforeLt, because it might be an imported constant sub β€” even though it's honestly way more likely to just be a simple mis-ordering, which use strict picks up anyway when it runs. so the policy is being extra, and that's fine. πŸ’…


πŸ¦‹ 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/>.


ok that's the whole page bestie, we ate and left zero crumbs πŸ“ β€” this manual page came to you courtesy of perl v5.40.1, dated 2025-10-21, mwah πŸ’–

πŸ“¦ where this page comes from