Perl 向多行引用的单词添加注释的最佳方式是什么?
起点:Perl 向多行引用的单词添加注释的最佳方式是什么?,perl,Perl,起点: my @array=qw(word1 word2 word3); 现在我想把每个单词放在单独的一行: my @array=qw( word1 word2 word3 ); 现在我想添加评论: my @array=qw( word1 # This is word1 word2 # This is word2 word3 # This is word3 ); 当然,上述方法不起作用,会生成带有“使用警告”的警告 那么,从上面的注释列表中创建数组的最佳
my @array=qw(word1 word2 word3);
现在我想把每个单词放在单独的一行:
my @array=qw(
word1
word2
word3
);
现在我想添加评论:
my @array=qw(
word1 # This is word1
word2 # This is word2
word3 # This is word3
);
当然,上述方法不起作用,会生成带有“使用警告”的警告
那么,从上面的注释列表中创建数组的最佳方法是什么呢?我建议避免使用
qw
my @array = (
'word1', # This is word1
'word2', # This is word2
'word3', # This is word3
);
但是你可以用
或者自己解析
sub myqw { $_[0] =~ s/#[^\n]*//rg =~ /\S+/g }
my @array = myqw(q(
word1 # This is word1
word2 # This is word2
word3 # This is word3
));
sub myqw { $_[0] =~ s/#[^\n]*//rg =~ /\S+/g }
my @array = myqw(q(
word1 # This is word1
word2 # This is word2
word3 # This is word3
));