Hi Doctrin,
as others have pointed out, you are suffering from autovivification. In order to avoid autovivification in your specific case, you could also check each level of the hash for existence before dereferencing it (and therefore before autovivification is triggered). The code could look like this:
It takes advantage of the fact that the && s inside the condition are evaluated from left to right, and the evaluation is aborted once a "false" occurs.if (exists $Hash{$neededVal} && exists $Hash{$neededVal}{param1} && ex +ists $Hash{$neededVal}{param1}{key1}) { print "DEFINED\n"; }
HTH, Rata
In reply to Re: Checking if hash value exists without implicitly defining it
by Ratazong
in thread Checking if hash value exists without implicitly defining it
by Doctrin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |