Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 56633
Status: resolved
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: JARIAALTO [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Capture variable used outside conditional (false positive)
Capture variable used outside conditional at line 9, column 12. See page 253 of PBP. 1 #!/usr/bin/perl 2 use strict; 3 4 unless ( /$copyright($yyyy)/oi ) 5 { 6 # rest of the code 7 } 8 9 my $year = $1; The "$1" is accessible after "unless" or "if".
Subject: Re: [rt.cpan.org #56633] Capture variable used outside conditional (false positive)
Date: Thu, 15 Apr 2010 08:13:29 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
On 4/15/10 6:56 AM, Jari Aalto via RT wrote: Show quoted text
> Capture variable used outside conditional at line 9, column 12. See > page 253 of PBP. > > 1 #!/usr/bin/perl > 2 use strict; > 3 > 4 unless ( /$copyright($yyyy)/oi ) > 5 { > 6 # rest of the code > 7 } > 8 > 9 my $year = $1; > > The "$1" is accessible after "unless" or "if".
The question isn't one of accessibility but of use.
On Thu Apr 15 09:13:42 2010, clonezone wrote: Show quoted text
> On 4/15/10 6:56 AM, Jari Aalto via RT wrote:
> > Capture variable used outside conditional at line 9, column 12. See > > page 253 of PBP. > > > > 1 #!/usr/bin/perl > > 2 use strict; > > 3 > > 4 unless ( /$copyright($yyyy)/oi ) > > 5 { > > 6 # rest of the code > > 7 } > > 8 > > 9 my $year = $1; > > > > The "$1" is accessible after "unless" or "if".
> > The question isn't one of accessibility but of use.
?? This policy's docs read: 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. Is the code not testing the success status, thus verifying that $1 is available?
On Thu Apr 15 11:52:06 2010, JARIAALTO wrote: Show quoted text
> On Thu Apr 15 09:13:42 2010, clonezone wrote:
> > On 4/15/10 6:56 AM, Jari Aalto via RT wrote:
> > > Capture variable used outside conditional at line 9, column 12.
See Show quoted text
> > > page 253 of PBP. > > > > > > 1 #!/usr/bin/perl > > > 2 use strict; > > > 3 > > > 4 unless ( /$copyright($yyyy)/oi ) > > > 5 { > > > 6 # rest of the code > > > 7 } > > > 8 > > > 9 my $year = $1; > > > > > > The "$1" is accessible after "unless" or "if".
> > > > The question isn't one of accessibility but of use.
> > > ?? > > This policy's docs read: > > If a regexp match fails, then any capture variables (`$1', ` > $2', ...) > will be undefined. Therefore it's important to check the
return Show quoted text
> value of > a match before using those variables. > > Is the code not testing the success status, thus verifying that $1 is > available? >
Nope. I was wrong. Of course it falls through. Thanks.