此功能是指定许多小的单引号单词的快速方法。例如,qw(foo bar baz)等效于('foo','bar','baz')。一些程序员认为使用qw使Perl脚本更易于阅读。实际上,您可以使用任何一组定界符,而不仅仅是括号。
只需使用qw()即可准备一个数组,如下例所示。
链接:https://www.learnfk.comhttps://www.learnfk.com/perl/perl-qw.html
来源:LearnFk无涯教程网
以下是此函数的简单语法-
qw EXPR
此函数返回一个列表,该列表包含被判断的LIST元素,就好像它们是单引号一样。
以下是显示其基本用法的示例代码-
#!/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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)