Perl::...quality(3pm)

πŸ“¦
version 1.003 Β· 2 versions
, in fedora 43

✨ NAME ✨

So bestie, welcome to the Perl::...quality(3pm) page from the User Contributed Perl Documentation collection πŸ’– Today's main character is:

Perl::Critic::Policy::ValuesAndExpressions::RequireConstantOnLeftSideOfEquality β€” putting the constant value on the left side of an equality exposes typos. Periodt. πŸ’…


πŸŽ€ AFFILIATION πŸŽ€

This policy is part of Perl::Critic::More, a bleeding edge supplement to Perl::Critic. It's giving ✨ bonus content ✨ energy, iykyk.


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the tea β˜• β€” this policy yells at you (well, warns you) if you put a constant value, like a literal number or some string, on the right side of a == operator when there's a variable or some other lvalue chilling on the left side. In a nutshell:

if($foo == 42){}    # not ok
if(42 == $foo){}    # ok

if($foo eq 'bar'){} # not ok
if('bar' eq $foo){} # ok

The rationale, bestie, is that sometimes you might mistype = instead of == 😭, and if you're in the habit of putting the constant value on the left side of the equality, then Perl will give you a compile-time warning. Honestly this is best explained with an example, so:

if ($foo == 42){}  # This is what I want it to do.
if ($foo = 42){}   # But suppose this is what I actually type.
if (42 = $foo){}   # If I had (mis)typed it like this, then Perl gives a warning.
if (42 == $foo){}  # So this is what I should have attempted to type.

So real talk: this Policy doesn't actually tell you if you've mistyped = instead of ==. Not its job, no cap. Rather, it encourages you to write your expressions in a certain way so that Perl can warn you when you mistyped it. It's not a detective, it's a hype squad for good habits 🫢

And now the plot twist 🌈 β€” the eq operator is not prone to the same type of typo as the == operator, but this Policy still treats it the same way. Therefore, the rule is consistently applied to all equality operators, which helps you to get into the habit of writing compliant expressions faster. Consistency slay πŸ’…βœ¨


πŸ’œ CONFIGURATION πŸ’œ

Not me being boring for once πŸ™ˆ β€” this Policy is not configurable except for the standard options.


πŸ‘‘ AUTHOR πŸ‘‘

Jeffrey Ryan Thalhammer <thaljef@cpan.org> β€” iconic, we stan πŸ’–


Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.


ok that's the whole page bestie, every last detail preserved, nothing skipped, vibe check passed ⭐

perl v5.42.0 Β· 2025-07-25 Β· Perl::...quality(3pm) β€” mwah, bye bestie πŸ’‹πŸ§šβ€β™€οΈπŸ“

πŸ“¦ where this page comes from