$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        


In reply to Re^5: Warnings not being thrown with DBI (nits) by tye
in thread Warnings not being thrown with DBI by hubb0r

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.