Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable warning about literal commas in qw list

Tags:

perl

my @flavors = qw/sweet,sour cherry/;

yields "Possible attempt to separate words with commas" - how can I disable that warning in cases where I want literal commas?

like image 680
gcbenison Avatar asked Oct 24 '13 18:10

gcbenison


2 Answers

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/);
like image 95
toolic Avatar answered Oct 14 '22 10:10

toolic


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
);
like image 6
ikegami Avatar answered Oct 14 '22 11:10

ikegami