shamat has asked for the wisdom of the Perl Monks concerning the following question:
prints:use strict; use warnings; use Data::Dumper; my %hash_data = (); my $key1 = "a"; my $key2 = "1"; my $key3 = "B"; my $key4 = "_"; if (exists $hash_data{$key1}{$key2}{$key3}{$key4}) { print "exists\n"; } else { print "DOES NOT EXIST\n" } print "-----\n"; print Dumper (\%hash_data);
It looks like some sub-keys are generated (in this case $k1,$k2,$k3) if they don't exist. How can I avoid that? Thanks for sharing your wisdom!DOES NOT EXIST ----- $VAR1 = { 'a' => { '1' => { 'B' => {} } } };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: question on hash behavior
by toolic (Bishop) on May 03, 2016 at 16:49 UTC | |
|
Re: question on hash behavior
by AnomalousMonk (Archbishop) on May 03, 2016 at 20:18 UTC | |
|
Re: question on hash behavior
by BillKSmith (Monsignor) on May 03, 2016 at 18:28 UTC | |
|
Re: question on hash behavior
by perlingRod (Novice) on May 03, 2016 at 17:25 UTC | |
by shamat (Acolyte) on May 04, 2016 at 06:07 UTC |