使用Perl6散列键定义与存在

前端之家收集整理的这篇文章主要介绍了使用Perl6散列键定义与存在前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在从Perl5学习Perl6.

我在看副词:存在https://docs.perl6.org/type/Hash#:exists,但没有:定义的副词

但我很担心,因为perl5的存在和存在之间有区别.定义:What’s the difference between exists and defined?

我怎样才能在Perl6中做这样的事情?

if (defined $hash{key}) {
   $hash{key}++;
} else {
   $hash{key} = 1;
}

解决方法

if defined %hash{'key'} {
   %hash{'key'}++;
} else {
   %hash{'key'} = 1;
}

使用定义的例程或方法.见5to6-perlfunc — defined

猜你在找的Perl相关文章