Multiple choice technology programming languages

What will be the value of $keys ? my $var; if (exists $var->{key1}->{key2}) { $var->{key1}->{key2} = 1; } my $keys = keys(%{$var});

  1. code will fail

  2. 2

  3. 1

  4. undef

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The expression exists $var->{key1}->{key2} triggers autovivification of $var->{key1} as a hash reference, even though the overall exists check evaluates to false. Thus, %{$var} contains exactly one key (key1), making keys(%{$var}) return 1 (596756).