I read as far as your premise. It's wrong. To test if a scalar has been set use:
if (defined $scalar) {
To test if a hash key/value pair exists use:
if (exists $hash{key}) {
To test if the scalar content of a hash value has been set use:
if (defined $hash{key}) {
Those last two steps can be combined:
if (exists $hash{key} && defined $hash{key}) {
and of course you can make the same tests with a multi-dimensional hash:
if (exists $hash{key1}{key2} && defined $hash{key1}{key2}) {
This last example is interesting if key1 didn't exist - it pops into existence. This is a process called autovivification and happens when Perl needs to have a hash or array element in order to write to it or use it to access an element is references.
In reply to Re: Best Multidimensional Hash Practices?
by GrandFather
in thread Best Multidimensional Hash Practices?
by DamianKaelGreen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |