目录

qw

描述 (Description)

此功能是指定大量小单引号单词的快捷方式。 例如,qw(foo bar baz)相当于('foo','bar','baz')。 一些程序员觉得使用qw使Perl脚本更容易阅读。 您实际上可以使用任何一组分隔符,而不仅仅是括号。

您只需使用qw()来准备数组,如下例所示。

语法 (Syntax)

以下是此函数的简单语法 -

qw EXPR

返回值 (Return Value)

此函数返回一个列表,该列表由LIST元素组成,评估为单引号。

例子 (Example)

以下是显示其基本用法的示例代码 -

#!/usr/bin/perl -w
@array = qw(This is a list of words without interpolation);
foreach $key (@array) {
   print"Key is $key\n";
}

执行上述代码时,会产生以下结果 -

Key is This
Key is is
Key is a
Key is list
Key is of
Key is words
Key is without
Key is interpolation
↑回到顶部↑
WIKI教程 @2018