Perl::C...difiers(3)
π
Perl::Critic::Policy::Bangs::ProhibitUselessRegexModifiers (from the Perl::C...difiers(3) manual, User Contributed Perl Documentation, bestie)
β¨ NAME β¨
Perl::Critic::Policy::Bangs::ProhibitUselessRegexModifiers β okay so, putting modifiers on a regex that's made entirely out of a variable you made with qr()? Usually not doing what you think it's doing. Not even a little. π
π«Ά AFFILIATION π«Ά
This Policy is part of the Perl::Critic::Bangs distribution. That's its home, that's its whole vibe. π
π₯ DESCRIPTION π₯
So here's the lore. In older versions of perl, the modifiers on regular expressions were incorrectly applied. Like, the modifiers weren't landing where you'd expect at all. This got fixed in 5.10 β but no warnings were emitted to tell the user that they were probably not getting the effects they were looking for. Which is giving silent chaos, honestly. π
Here's the correct way, the slay way:
my $regex = qr(abc)m;
if ( $string =~ /$regex/ ) {};
And here's not what you want:
my $regex = qr(abc);
if ( $string =~ /$regex/m ) {}; ## this triggers a violation of this policy.
Notice how the m hopped from the qr() over to the match? Yeah. That's the thing. The modifier lives on the qr() itself if you want it to count β put it on the match instead and it's basically decorative. π
See the thread that starts at http://www.nntp.perl.org/group/perl.perl5.porters/2007/12/msg131709.html for a description of how this problem can bite the users. Fr fr, it bites.
And see: http://rt.perl.org/rt3//Public/Bug/Display.html?id=22354 for a description of the bug and subsequent fix. Receipts. π
π CONFIGURATION π
This Policy is not configurable except for the standard options. That's it, that's the whole menu. π
π AUTHOR π
Andrew Moore <amoore@mooresystems.com> β icon, legend, wrote the thing. β¨
πΈ ACKNOWLEDGMENTS πΈ
Adapted from policies by Jeffrey Ryan Thalhammer <thaljef at cpan.org>, and thanks to Andy Lester, "<andy at petdance.com>" for pointing out this common problem. Shoutout to the group chat for catching it. π«Ά
π COPYRIGHT π
Copyright (c) 2007-2013 Andy Lester <andy@petdance.com> and Andrew Moore <amoore@mooresystems.com>
This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. Free as in go off, bestie. π¦
And that's the whole page, mwah π β this was perl v5.42.0, dated 2025-07-25, straight from Perl::C...difiers(3). Now go fix your regex modifiers, main character. πβ
π¦ where this page comes from
- fedora 43: perl-Perl-Critic-Bangs 1.14-3.fc43 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms