What's the difference between exists and defined?

后端 未结 5 2038
花落未央
花落未央 2020-12-07 14:24

What is the difference between

if (defined $hash{$key}) { }

and

if (exists $hash{$key}) { }

When do I kno

5条回答
  •  猫巷女王i
    2020-12-07 15:23

    Perl documentation:

    When used on a hash element, defined tells you whether the value is defined, not whether the key exists in the hash. Use exists for the latter purpose.

提交回复
热议问题