in reply to Re: Check for existance in a hash of hashes
in thread Check for existance in a hash of hashes

$a{foo}{bar} = 'blah'; print "Yep\n" if exists $a{foo} && $a{foo}{bar}; print "Nope\n" if exists $a{bar}{baz}; print "Whoops!\n" if exists $a{bar};

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Re2: Check for existence in a hash of hashes
by Fletch (Bishop) on Mar 27, 2002 at 18:51 UTC

    You've created $a{bar} by your second check, just as perldoc -f exists explains.

    Although the deepest nested array or hash will not spring into existence just because its existence was tested, any intervening ones will. Thus "$ref->{"A"}" and "$ref->{"A"}->{"B"}" will spring into existence due to the existence test for the $key element above. This happens anywhere the arrow operator is used, including even:...
      I know that. You know that. Did the original poster know that? Did all the readers of this thread know that?

      When you post a solution, you should post the common caveats, gimmes, and gotchas as well. Otherwise, those who may not be as fluent as the saints will get frustrated.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.