http://www.perlmonks.org?node_id=491077


in reply to Re^4: Warnings not being thrown with DBI (nits)
in thread Warnings not being thrown with DBI

$href->{id} is being autovivified (it wasn't there before, it is there afterward). The expression, $href->{id}, by itself, isn't enough to make the autovification happen. I just showed one way it can be autovivified. It doesn't require that method.

Claiming that hash entries are never autovivified, seeing a check of a hash entry used to autovivify an entry in a hash, and then claiming no conflict is pretty fine hair splitting in my book, especially when you started the picking of the nits.

Since the original code did not show the code for execute(), I was just showing that that exact code certainly could autovivify $hash->{id}.

main->execute( $href->{id} ); sub execute { my $sum= 0; for( @_ ) { $_ ||= 0; $sum += $_; } return $sum; } print keys %$href, $/;

(prints "id")

It is actually somewhat complex magic that allows the undef that gets passed into execute() to be able to autovivify the hash entry at quite a distance (and thus also allows the autovivification to be avoided in some cases).

The lack of immediate autovivification is actually in conflict with the documentation, IMHO, because $href->{id} is being used in an lvalue context just by virtue of being passed directly to a function. I'll have to dig up some old versions of Perl, because I believe the autovivification used to happen immediately instead of being delayed by such magic. I also found a bug in this magic in a node a few years ago...

- tye