I don't use
exists $hashtest{abc} and defined $hashtest{abc} because
defined can handle
undef. However, sometimes I do
defined $hashtest{abc} and $hashtest{abc} because I want the
false condition to be based on more than
$hashtest{abc} being
undef. I also want it to evaluate to
false if it's an empty string or
0, in addition to
undef. In that case because the second condition is not protected by
defined I need to make sure that the key exists. TBH I don't remember the last time I even used
exists.
To summarize:
# generally pointless, I would not use the mere existence of the key t
+o mean anything; check it's value
if ( exists $hashtest{abc} and defined $hashtest{abc} ) {
print qq{This is worthless IMO.\n};
}
Rather just do this if
undef is taken as
does not exist.
if (defined $hashtest{abc}) {
print qq{Better than 'exists'; check for the value being undef or no
+t undef.\n};
}
And if I want to check the value, something like:
if (defined $hashtest{abc} and $hashtest{abc}) {
print qq{Also, better than 'exists' and when I want to make sure the
+ value is not "falsey"\n};
}