当前位置:首页 » Perl » Perl exists()函数

Perl exists()函数

perl exists()函数,exists()函数学习例子,exists()函数实例代码,exists()函数在线教程等

语法

exists EXPR


定义和使用

指定的哈希或数组的键,则返回true,如果存在,不管相应的值,即使它是undef。如果EXPR是一个子程序,则存在将返回1,如果在子程序声明(但不一定定义),否则为0。

返回值

  • 0 - 哈希(hash)元素或数组索引如果不存在,或如果尚未声明的子程序

  • 1- 如果不存在哈希(hash)元素或数组索引,或者如果子程序没有被声明

例子

以下是使用用法...

    print "Exists\n" 	if exists $hash{$key};
    print "Defined\n" 	if defined $hash{$key};
    print "True\n"      if $hash{$key};

    print "Exists\n" 	if exists $array[$index];
    print "Defined\n" 	if defined $array[$index];
    print "True\n"      if $array[$index];
    
    #by www.gitbook.net
    print "Exists\n" 	if exists &subroutine_name;
    print "Defined\n" 	if defined &subroutine_name;