出发点:
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
);
但是你可以使用 Syntax::Feature::QwComments .
use syntax qw( qw_comments );
my @array = qw(
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
));
关于perl - 为多行引用的单词添加注释的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23474653/