2014-05-05 43 views
4

起點:向多行引用詞添加註釋的最佳方式是什麼?

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 
); 

以上課程的不起作用,併產生警告使用警告

那麼,從上面的註釋列表中創建數組的最佳方式是什麼?

回答

6

我建議避免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 
)); 
相關問題