in reply to Re: Unexpected exists() behavior
in thread Unexpected exists() behavior

Testing for hash{priKey} before the full test is my workaround solution already in the works. It just seemed odd to me that a function with the sole purpose of testing would create an entry under the correct circumstances. Any idea when / why that would be desired behavior?

Replies are listed 'Best First'.
Re^3: Unexpected exists() behavior
by jeffa (Bishop) on Jun 22, 2006 at 16:51 UTC

      That doesn't technically count as autovivification, though; that's undef being treated as 0 in a numeric context. Autovivification is the automatic creation of a reference to a new anonymous hash (or array) when required to implement a multilevel data structure.</pedant>

      Update: And to out pedant myself, you don't necessarily have to have a multilevel structure; my $aref; push @{ $aref }, 1; is autovivification as well. The Uri article referenced from the node I mentioned below uses the phrasing automatically creating a reference of the appropriate type whenever a scalar containing undef is dereferenced. Better than what I used above.

      Further update: The parent did have code using $hash{ $_ }++ and calling that autovivification. It's been removed so this now will make less sense. Ah well.