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: 69867
Status: resolved
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: Mark.Martinec [...] ijs.si
Cc:
AdminCc:

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



Subject: RegularExpressions::ProhibitUnusedCapture false positive when capture used in an else branch
Date: Thu, 28 Jul 2011 18:45:27 +0200
To: bug-Perl-Critic [...] rt.cpan.org
From: Mark Martinec <Mark.Martinec [...] ijs.si>
FreeBSD 8.2, perl 5.14.1, Perl::Critic 1.116 $ perlcritic -3 use strict; use warnings; # false positive: RegularExpressions::ProhibitUnusedCapture my($ip, @fields); if ($ip !~ /^(.*?)::(.*)\z/sx) { @fields = split(/:/x, $ip); } else { my($before,$after) = ($1,$2); # ... } Only use a capturing group if you plan to use the captured value at line 6, column 14. See page 252 of PBP. (Severity: 3) Mark
Thank you for your report. At this point, it appears to me that the policy is being confused by the regular expression in the split() call. This may take a bit to sort out, since it appears to me that the real problem is that the policy should not look at the 'if' block at all in this case. And in the more normal ( =~ ) case it should not look at the 'else' block. Pending resolution, there's always a '## no critic (ProhibitUnusedCapture)' annotation, or (if practicable) restructuring the code to use 'if ($ip =~ /^(.*?)::(.*)\z/sx) ...'. Tom
Patched in svn commit 4091. The fix was to skip analysis of the first block after an 'if' or 'elsif' if the regular expression was bound to its operand with a '!~'. I think that technically it should only analyze the first block after an 'if' or 'elsif' if the regexp was not bound with a '!~', but I left that for another day.
This was fixed and released as Perl-Critic-1.117 -- Jeffrey Thalhammer Imaginative Software Systems www.imaginative-software.com