Hello!

Here is the program, and below results for perl 5.24 and 5.28:

#!/usr/bin/perl -CSDA use utf8; use Modern::Perl qw{2017}; no autovivification qw{fetch store exists delete}; my $h = { 'a' => { 'p' => 2, 'q' => 3, }, }; print "perl ver $]:\n"; $$h{a} and print "a ok\n"; ! $$h{b} and print "b not\n"; ! $$h{a}{x} and print "a/x not\n"; ! $$h{a}{x}{z} and print "a/x/z not\n"; perl ver 5.024001: a ok b not a/x not a/x/z not perl ver 5.028001: a ok b not a/x not Can't vivify reference at ./atest line 18.

Could someone please explain what has changed between 5.24 and 5.28 in regard of autovivification? And what would be the proper way to check existence of value in last line in ver 5.28?

ver 5.24 good way: ! $$h{a}{x}{z} and print "a/x/z not\n"; ver 5.28 good (?) way: ! ( $$h{a} && $$h{a}{$x} && $$h{a}{x}{z}) and print "a/x/z not\n"; # + ?? any better idea?

PS. I have to prevent perl from modifying my data structure "behind the scenes", because that structures get mapped to textual data that goes to manufacturing management system, and if any undef is inside data structure then error is thrown, because that means that someone made something wrong.


In reply to 5.24 -> 5.28 -- what has changed in autovivification? by leszekdubiel

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.