加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – 为多行引用词添加注释的最佳方法是什么?

发布时间:2020-12-16 06:26:25 所属栏目:大数据 来源:网络整理
导读:出发点: 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
);

但你可以使用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
));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读