in reply to Re: How to Check Hashes for Missing Items when Keys can be Values and vice versa
in thread How to Check Hashes for Missing Items when Keys can be Values and vice versa

trying to understand the perldoc description givees me too much of a headache:-

A hash or array element can be true only if it's defined and defined only if it exists, but the reverse doesn't necessarily hold true.

here's a Venn(ish) diagram in beautiful ASCII art that may or may not help, with examples on the side

universe of possible hash elements in Perl +--------------------------------------+ | elements that exist | $hash{element_exis +ts}; # this example: exists, undefined, false | +--------------------------------+ | | | elements that are defined | | $hash{element_defi +ned} = function_def();# this example: exists, defined, unknown false/ +true | | +--------------------------+ | | | | | elements that are true | | | $hash{element_true +} = 1; # this example: exists, defined, true | | +--------------------------+ | | | | | | | | +--------------------------+ | | | | : elements that are false : | | $hash{element_fals +e} = function_false();# this example: exists, defined, false | | : +-------------------+ : | | | | : | false but defined | : | | $hash{element_fals +e_defined} = 0; # this example: exists, defined, false | | : +-------------------+ : | | | +--:--------------------------:--+ | | : : | | +--:--------------------------:--+ | | | : +-------------------+ : | | | | : | false but undef | : | | $hash{element_fals +e_undefined} = undef; # this example: exists, undefined, false | | : +-------------------+ : | | | | +--------------------------+ | | | | elements that are undefined | | $hash{element_unde +fined}; # this example: exists, undefined, false | +--------------------------------+ | +--------------------------------------+

Note that the ASCII art combined with wanting space for labels sometimes implies there is room in the Perl universe for combinations that aren't actually possible: for example, there are no elements that are undefined but not false, because perl coerces undefined to false.

  • Comment on Re^2: How to Check Hashes for Missing Items when Keys can be Values and vice versa
  • Download Code