使用 grep 或 map 将数组元素映射到哈希键

There's more than one way to do it!
https://metacpan.org http://perlmonks.org
回复
头像
PerlMonk
渐入佳境
渐入佳境
帖子: 49
注册时间: 2016年09月19日 10:20
联系:

使用 grep 或 map 将数组元素映射到哈希键

帖子 PerlMonk »

my %hash;
grep { $hash{$_} = 1 } ('a' .. 'd');
而使用 map 更直接(如果数组不是非常庞大的话):
my %hash = map { $_, 1 } ('a' .. 'd');
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 7 访客