跳转到内容

Perl 编程/关键字/qw

来自维基教科书,开放世界中的开放书籍
上一个:quotemeta 关键字 下一个:qx

qw关键字

[编辑 | 编辑源代码]

qw是一个可以用来替换引号(")符号的命令。

  qw(element [element] […])
代码
my @array = qw(one two three);

print "Array contains " . @array . " element" . ((@array == 1) ? "" : "s") . "\n";
my @array1 = "only";

print "Array1 contains " . @array1 . " element" . ((@array1 == 1) ? "" : "s") . "\n";
my @family = "father, mother, daughter, son";

print "The family has " . @family . " member" . ((@family == 1) ? "" : "s") . "\n";

print qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[2] . "\n";
返回数组中的元素数量和第三个月份,如下所示
Array contains 3 elements
Array1 contains 1 element
The family has 1 member
Mar


上一个:quotemeta 关键字 下一个:qx
华夏公益教科书