But defined doesn't do anything to prevent autovivification either. Look at this:
my %hash = ( Key1 => { john => 1, pete => 2 }, Key2 => { frank => 3, howard => 4 } ); print "Exists!\n" if defined $hash{Key7}{ted}; print "Key7 exists!\n" if exists $hash{Key7};
Here you're testing the definedness of a key that doesn't exist: $hash{Key7}{ted}, and then you're going to check to see if $hash{Key7} autovivified. Guess what? It did, just the same as when we used exists to check for the existance of $hash{Key7}{ted}. The same conditions that will cause exists to autovivify a hash element will also cause defined to autovivify a hash element. exists doesn't have any more possibility to do that than any other function.
Dave
In reply to Re^4: need explanation of @foo{@bar} = (); (hash slice)
by davido
in thread need explanation of @foo{@bar} = (); (hash slice)
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |