I think in older perl5's, $h->{x} might have been autovivified and set to undef in the defined case, but never in the exists case ... unless I'm misremembering something.
No (yes, you are misremembering). Despite having seen many warnings for people to use defined and/or exists, these have never explicitly prevented autovivification. They can indirectly prevent autovivification by preventing a sneaky "lvalue context" situation, but they aren't special in this regard as just about any expression will do that as well, for example, " '' .... ". And, of course, nearly all of these cases of "wrapping in an expression" change the results. A possible exception is scalar, which prevents lvalue context while not changing the value returned (if dealing with a scalar expression, of course).
So, sometimes you can avoid one level of autovivification by using a less direct expression, but:
I think at some point someone was pointed to insert a use of exists in order to gain a level of indirection such that $hash{key} would no longer be in an "lvalue context" and this advice got misinterpretted as exists having some magic power (or just an intentional feature) to prevent autovivification. That has never been the case. Though, there is talk of making exists special such that it can prevent more levels of autovivification (but I'm not holding my breath on that, personally).
- tye
In reply to Re^10: searching a list (myth)
by tye
in thread searching a list
by keiusui
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |