Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
Perl::Critic:Perl::CriUser:ContributeduPerlxDocumentationohibitUselessTopic(3)

NAME
       Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic -	Don't
       use $_ to match against regexes.

AFFILIATION
       This Policy is part of the Perl::Critic distribution.

DESCRIPTION
       It is not necessary to specify the topic	variable $_ when matching
       against a regular expression.

       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 $_.

	   # 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.

	   # These are identical
	   if (	$_ !~ /DEBUG/ )	{ ...
	   if (	!/DEBUG	) { ...

       Including the "$_ =~" or	"$_ !~"	is unnecessary,	adds complexity, and
       is not idiomatic	Perl.

CONFIGURATION
       This Policy is not configurable except for the standard options.

AUTHOR
       Andy Lester <andy@petdance.com>

COPYRIGHT
       Copyright (c) 2013 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.

perl v5.24.1 Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic(3)

NAME | AFFILIATION | DESCRIPTION | CONFIGURATION | AUTHOR | COPYRIGHT

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic&sektion=3&manpath=FreeBSD+12.1-RELEASE+and+Ports>

home | help