disable warning about literal commas in qw list
You could use no warnings 'qw';
.
my @x = do {
no warnings qw( qw );
qw(
a,b
c
d
)
};
Unfortunately, that also disables warnings for #
. You could have #
mark a comment to remove the need for that warning.
use syntax qw( qw_comments );
my @x = do {
no warnings qw( qw );
qw(
a,b
c
d # e
)
};
But it's rather silly to disable that warning. It's easier just to avoid it.
my @x = (
'a,b',
'c',
'd', # e
);
or
my @x = (
'a,b',
qw( c d ), # e
);
Just don't use qw//
but one of the plenty other quoting operators, paired with a split
. How does q//
sound?
my @flavours = split ' ', q/sweet,sour cherry/;
The qw//
is just a helpful shortcut, but it's never necessary to use it.
In a case where I was developing a framework where lists of comma separated keywords was pretty commonplace, I chose to surgically suppress those warnings at the signal handler.
$SIG{__WARN__} = sub {
return
if $_[0] =~ m{ separate words with commas };
return CORE::warn @_;
};
Disable the warnings locally:
my @flavors;
{
no warnings 'qw';
@flavors = qw/sweet,sour cherry/;
}
Or, separate out those with commas:
my @flavors = ('sweet,sour', qw/cherry apple berry/);