Perl::...sTopic(3pm)
π NAME π
okay so this is the Perl::...sTopic(3pm) page from the User Contributed Perl Documentation, and it's here to talk about the Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic policy, bestie: don't use $_ to match against regexes. No cap. π
πΈ AFFILIATION πΈ
This Policy is part of the Perl::Critic distribution. It's giving official family member energy. π«Ά
β¨ DESCRIPTION β¨
It is not necessary to specify the topic variable $_ when matching against a regular expression. lowkey it's just extra.
Match or substitution operations are performed against variables, such as:
$x =~ /foo/;
$x =~ s/foo/bar/;
$x =~ tr/a-mn-z/n-za-m/;
If a variable is not specified, the match is against $_. iykyk π¦
# These are identical.
/foo/;
$_ =~ /foo/;
# These are identical.
s/foo/bar/;
$_ =~ s/foo/bar/;
# These are identical.
tr/a-mn-z/n-za-m/;
$_ =~ tr/a-mn-z/n-za-m/;
This applies to negative matching as well. slay β¨
# These are identical
if ( $_ !~ /DEBUG/ ) { ...
if ( !/DEBUG ) { ...
Including the "$_ =~" or "$_ !~" is unnecessary, adds complexity, and is not idiomatic Perl. Periodt. It's giving clutter, not main character energy. π
π CONFIGURATION π
This Policy is not configurable except for the standard options. so no extra knobs, babes. π
π¦ AUTHOR π¦
Andy Lester <andy@petdance.com> β iconic. π
π COPYRIGHT π
Copyright (c) 2013-2023 Andy Lester <andy@petdance.com>
This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.
π and that's the whole page, bestie β brought to you by perl v5.42.0, dated 2024-10-23, from the User Contributed Perl Documentation. mwah! π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Perl-Critic 1.156.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms