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: