in reply to Are defined or // garantee not to autovivify?

Hash elements are created when accessed in lvalue context. Here are examples of hash values used in lvalue context:

$hash{$key} = ...; ++$hash{$key}; for ($hash{$key}) { ... } \$hash{$key} some_sub($hash{$key}) # Exception!! See footnote.

// doesn't create an lvalue context for its operands, not even if it's evaluated in an lvalue context itself.

$ perl -e'my %h; 1 for $h{k}; CORE::say 0+keys(%h)' 1 $ perl -e'my %h; 1 for $x // $h{k}; CORE::say 0+keys(%h)' 0

  1. When passing a hash value to a sub, Perl specifically avoids creating the hash element until necessary. This means that some_sub($hash{$key}) doesn't create $hash{$key} unless the sub does something like $_[0] = "abc";.