You access complex structures with %flag_assignments as the root. Perl will helpfully bring intermediate elements into life automatically ("autovivify") if they don't exist.

In the following code, if $flag_assignments{$temp_key} does not exist, it will get autovivified due to its use a few lines later:

... if (defined $flag_assignments{$temp_key}) { print "KEY [$key] TK [$temp_key] TS [$temp_semester] FAS [$fla +g_assignments{$temp_key}{starrez}] FAA [$flag_assignments{$temp_key}{ +abbreviation}]\n"; } # Here it is possible that $flag_assignments{$temp_key} does not e +xist # ONLY ONE FLAGE PER CATEGORY, AND GREEKS LIVING ON CAMPUS WILL AL +SO GET NR ACCESS TO THE HOUSE OF THE FRAT/SORORITY if ($starrez{$key}{"dorm"} ne "None") { # Here, autovivification of a value for $flag_assignments{$tem +p_key} happens # because it's part of $flag_assignments{$temp_key}{$temp_seme +ster} if ($flag_assignments{$temp_key}{$temp_semester} ne "") { ...

One approach to prevent autovivification is to use exists checks before accessing a complex data structure. Another could be to use Data::Diver. To prevent accidential autovivification, see autovivification.


In reply to Re: Not meaning to add values to a hash ("autovivification") by Corion
in thread Not meaning to add values to a hash by stu96art

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.