perl exist函数
Perl's exists() function is used to check whether an element in an array or hash exists. It can also be used to check for the existence of subroutines. exists will return true as long as the element has been initialized, and even if the element is undefined.
Perl的exist()函数用于检查数组或哈希中的元素是否存在。 它也可以用来检查子程序的存在。 只要元素已初始化,即使元素未定义,则存在将返回true。
In the above example, we look at a hash of our contact Bob and his phone number. First, we check for the existence of the phone element, which is obviously returning true. Next, we check for an element that does not exist, address, and you'll see this one returns false.Let's look at the same routine, but with a blank address key:
在上面的示例中,我们查看了联系人Bob和他的电话号码的哈希值。 首先,我们检查phone元素是否存在,显然返回true 。 接下来,我们检查一个不存在的元素address ,您将看到这个返回false 。让我们看一下相同的例程,但是有一个空白的address键:
You'll see that this one returns true on the address, even though there is no actual value. Be careful relying on the logic of exists, and remember the distinction between exists and has value.
您会看到,即使没有实际值,该地址也将返回true。 要小心依靠存在的逻辑,并记住存在与具有价值的区别。
翻译自: https://www.thoughtco.com/perl-exists-function-quick-tutorial-2641184
perl exist函数