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

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

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



Subject: RegularExpressions::ProhibitSingleCharAlternation overzealous when some but not all alternatives are single chars
This test program: #!/usr/bin/perl # $Id: $ use warnings; use strict; use 5.010; use Carp qw(croak); our $VERSION = 1; if (/(a|b|c|ab|bc)/xms) { say $1; } run through perlcritic -1, produces a warning 'Use [abc] instead of a|b|c'. That would makes sense if a|b|c were the only alternatives, but here there are several, of which some happen to be a single character and some are not. The warning should be restricted to cases where every alternative is exactly one character. If the above example doesn't convince you, and you feel it would be more readable rewritten as /([abc]|ab|bc)/, consider this one that is closer to the real-world code motivating this request: /\A(2|3|5|10|20|30)-yr announcement/ It's hard to argue that ([235]|10|20|30) is clearer or more readable, since it seems at first glance to involve the number 235. Shall I make a patch for this?
Subject: Re: [rt.cpan.org #48841] RegularExpressions::ProhibitSingleCharAlternation overzealous when some but not all alternatives are single chars
Date: Wed, 19 Aug 2009 22:35:34 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
EDAVIS via RT wrote: Show quoted text
> > /\A(2|3|5|10|20|30)-yr announcement/ > > It's hard to argue that ([235]|10|20|30) is clearer or more readable, > since it seems at first glance to involve the number 235. > > Shall I make a patch for this?
This type of thing has been discussed before and the decision was to not change it (in fact there was a bug fix for when it wasn't complaining, if I recall correctly). I agree that, in this example, the expanded form is more legible. However, this appears to be an exception. No policy is perfect. OTOH, if you want to add an exception that is controlled by a boolean option that defaults to false, I'll take the patch.