【发布时间】:2015-05-01 03:42:21
【问题描述】:
R 中是否有“引号”运算符,类似于 Perl 中的qw? qw 是一个引用运算符,允许您创建引用项目的列表,而无需单独引用每个项目。
如果没有qw(即使用几十个引号和逗号),您将如何做到这一点:
#!/bin/env perl
use strict;
use warnings;
my @NAM_founders = ("B97", "CML52", "CML69", "CML103", "CML228", "CML247",
"CML322", "CML333", "Hp301", "Il14H", "Ki3", "Ki11",
"M37W", "M162W", "Mo18W", "MS71", "NC350", "NC358"
"Oh7B", "P39", "Tx303", "Tzi8",
);
print(join(" ", @NAM_founders)); # Prints array, with elements separated by spaces
这里是做同样的事情,但qw 更简洁:
#!/bin/env perl
use strict;
use warnings;
my @NAM_founders = qw(B97 CML52 CML69 CML103 CML228 CML247 CML277
CML322 CML333 Hp301 Il14H Ki3 Ki11 Ky21
M37W M162W Mo18W MS71 NC350 NC358 Oh43
Oh7B P39 Tx303 Tzi8
);
print(join(" ", @NAM_founders)); # Prints array, with elements separated by spaces
我已经搜索过但没有找到任何东西。
【问题讨论】:
-
可能类似于
stringi::stri_split_boundaries或stri_extract_*_words。但如果知道qw()是做什么的,对于那些从未使用过 Perl 的人来说,那就太好了 -
感谢建议更好地解释
qw!刚刚编辑。