當前位置:首頁 » 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;