qw

定义和用法

qw()是用来指定了很多小单引号的句字是一个快速的方法。例如,qw(foo bar baz) 相当于 ('foo', 'bar', 'baz')。一些程序员认为,使用qw使Perl脚本更容易阅读。实际上,你可以使用任何分隔符,而不仅仅是括号组。

简单地,可以使用qw()准备一个数组,如以下所示的例示的。

返回值

  • 列表元素的列表组成的计算,如果他们是单引号。

例子

试试下面的例子:

#!/usr/bin/perl -w
#by www.yiibai.com

@array = qw(This is a list of words without interpolation);

foreach $key (@array){
   print"Key is $key
";
}

这将产生以下结果:

Key is This
Key is is
Key is a
Key is list
Key is of
Key is words
Key is without
Key is interpolation
原文地址:https://www.cnblogs.com/yuanjingnan/p/12418479.html