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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |