in reply to Why does testing a key create a hash?
It's autovivification. To test a hash key, you need to have a hash. Perl creates the hash, then checks the value of the key.
Depending on what you are doing, you probably want to check if the variable is defined.
print "Shouldn't print!\n" unless( defined $hash and ... );
However, if I know something is going to be a hash, I start with a hash.
my $hash = {};
|
|---|