任何人都可以帮助知道如何计算否。散列中的键,在 PERL 6 中?寻找没有手动循环的东西。
提前致谢!
编辑 : 到目前为止尝试了以下但没有运气。
my %hash = 1 => "one", 2 => <21,22,23>, 3 => "three" ;
my $count = %hash.keys [ makes it a flat list ]
my $count = %hash.count [no such method]
my $count = keys %hash [provides all the keys but not the count]
最佳答案
在 perl5 中,您可以将散列转换为标量,它就成为计数。你也可以在 perl6 中做到这一点:
%hash.Int;
# => 3
+%hash
# => 3
你也有 elems 方法:
%hash.elems;
# => 3
关于hash - 如何获得no的计数。 perl 6 %HASH 中的键数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42200927/