在qw列表中禁用有关文字逗号的警告

gcb*_*son 11 perl

my @flavors = qw/sweet,sour cherry/;
Run Code Online (Sandbox Code Playgroud)

产生"可能尝试用逗号分隔单词" - 如果我需要文字逗号,如何禁用该警告?

too*_*lic 16

在本地禁用警告:

my @flavors;
{
    no warnings 'qw';
    @flavors = qw/sweet,sour cherry/;
}
Run Code Online (Sandbox Code Playgroud)

更新:或者,用逗号分隔出来:

my @flavors = ('sweet,sour', qw/cherry apple berry/);
Run Code Online (Sandbox Code Playgroud)

  • 在这一点上,不使用`qw`会不会更容易? (4认同)

ike*_*ami 6

你可以用no warnings 'qw';.

my @x = do {
   no warnings qw( qw );
   qw(
      a,b
      c
      d
   )
};
Run Code Online (Sandbox Code Playgroud)

不幸的是,这也禁用了警告#.您可以#标记注释以消除对该警告的需要.

use syntax qw( qw_comments );

my @x = do {
   no warnings qw( qw );
   qw(
      a,b
      c
      d   # e
   )
};
Run Code Online (Sandbox Code Playgroud)

但禁用该警告是相当愚蠢的.避免它更容易.

my @x = (
   'a,b',
   'c',
   'd',   # e
);
Run Code Online (Sandbox Code Playgroud)

要么

my @x = (
   'a,b',
   qw( c d ),  # e
);
Run Code Online (Sandbox Code Playgroud)


amo*_*mon 5

只是不要使用qw//其他很多其他引用运算符,与a配对split.怎么q//声音?

my @flavours = split ' ', q/sweet,sour cherry/;
Run Code Online (Sandbox Code Playgroud)

qw//只是一个有用的捷径,但它永远不必使用它.