%{$hash{'wrong'}}; implies $hash{'wrong'} is a hash ref. Since $hash{'wrong'} is not defined, perl creates an anonymous hash for you and places a reference to it in $hash{'wrong'}. This is called Autovivification.
To avoid it here, do
print($hash{'wrong'} ? () : keys(%{$hash{'wrong'}}), "\n");
or
print(keys(%{$hash{'wrong'}}), "\n") if $hash{'wrong'};
depending if you want a blank line or no line at all.
In reply to Re: puzzling behaviour of keys function
by ikegami
in thread puzzling behaviour of keys function
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |