What if the element doesn't exist?
In a naive implementation, returning undef, zero, or an empty string from exists will fail dereference, and it would happen at runtime. A reference value that evaluates false, yet returns undef when dereferenced, seems to be required.
That seems to need a tricky sort of special-casing that would affect all dereferences.
Update: BrowserUK points out that dereferencing the return of exists yields undef. That does not pass use strict 'refs';, however. exists currently returns the empty string as false, generating Can't use string ("") as a SCALAR ref while "strict refs" in use at -e line 1..
Update 2: To clarify my point, this idea leads to:
giving assignment to the value without autovivification. The need to provide a reference which is false in bool context (for campatibility) is the basis for my objection.my %foo; my $bar = ${exists $foo{'bar'}};
After Compline,
Zaxo
In reply to Re: optimization - exists should return a reference
by Zaxo
in thread optimization - exists should return a reference
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |