Search code examples
raku

Defined vs. exists with Raku hash keys


I am learning Raku from Perl.

I am looking at the adverb :exists https://docs.raku.org/type/Hash#:exists but there isn't a :defined adverb

but I am concerned because there is a distinction between perl's exists & defined: What's the difference between exists and defined?

How can I do something like this in Raku?

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

Solution

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

    Use the defined routine or method. See 5to6-perlfunc -- defined