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?