Perl::Critic::Policy::RegularExpressions::ProhibitCaptureWithoutTest - Capture variable used outside conditional.
This Policy is part of the core Perl::Critic distribution.
If a regexp match fails, then any capture variables ($1, $2, ...) will be undefined. Therefore it's important to check the return value of a match before using those variables.
$1
$2
This policy checks that capture variables are inside a conditional and do not follow an regexps.
This policy does not check whether that conditional is actually testing a regexp result, nor does it check whether a regexp actually has a capture in it. Those checks are too hard.
This Policy is not configurable except for the standard options.
Needs to allow this construct:
for ( ... ) { next unless /(....)/; if ( $1 ) { .... } }
Right now, Perl::Critic thinks that the $1 isn't legal to use because it's "outside" of the match. The thing is, we can only get to the if if the regex matched.
if
while ( $str =~ /(expression)/ )
Chris Dolan <cdolan@cpan.org>
Copyright (C) 2006 Chris Dolan. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Perl::Critic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::Critic
CPAN shell
perl -MCPAN -e shell install Perl::Critic
For more information on module installation, please visit the detailed CPAN module installation guide.