On Sat, 23 Dec 2000, Graham Barr wrote:
> This has been discussed on p5p many many times. And many times
> I have agreed with what you wrote. However one thing you did not mention,
> but does need to be considered is
>
> func($x{1}{2}{3})
>
> at this point you do not know if this is a read or write access as
> the sub could do $_[0] = 'fred'. If this can be handled in someway
> so that the autoviv does not happen until the assignment then OK,
> but otherwise I think we would have to stick with perl5 semantics
This is a good point. Similar arguments apply to grep, map, foreach, etc.
Could we have some sort of "lazy evaluation" mode for lvalues where a
reference to an undefined substructure sets a flag and saves the expression
for the lvalue, returning undef whenever evaluated in a read-only context
and autovivifying when necessary to write to the lvalue?
> Also we would probably need a use autoviv pragma so that perl5
> scripts which are ported, and rely on the autivivify of hashes,
> will still work as before.
This makes sense, if any programs rely on the current behavior. (Do you
know of any such programs?)
Deven