Explanations and References to relevant information were already given by others. I would like to follow up, by an example, of how this can come back to bite you, and how you can avoid getting bitten :).
Consider the following code:
use strict; use warnings; use Data::Dumper; my %hash; if (exists $hash{foo}{bar}{element}) { print "It exists!\n" } print Dumper(\%hash);
It will output:
$VAR1 = { 'foo' => { 'bar' => {} } };
Testing for the existence of an element will autovivify all elements except for the last one, and then check whether it exists. Usually this is not the behaviour a programmer expects, when writing above code. In a more complex program with deeply nested data structure, this may created some confusion later on in the programm, since some elements will exist, even so there is no obvious reason why they should exist (until you learn about autovivification). if you want to avoid this, there is the no autovivification pragma on cpan.
use strict; use warnings; use Data::Dumper; no autovivification; # disables types of autovivification which are ty +pically not intended my %hash; if (exists $hash{foo}{bar}{element}) { print "It exists!\n" } print Dumper(\%hash);
With this one line added, the output will be as expected:
$VAR1 = {};

In reply to Re: Undef becomes hash reference somehow by rminner
in thread Undef becomes hash reference somehow by ipherian

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.