The exists function returns true if a hash key (or array index) has been defined, and false if not. : exists « Hash « Perl






The exists function returns true if a hash key (or array index) has been defined, and false if not.

    

#Format: exists $ASSOC_ARRAY{KEY}

#!/usr/bin/perl
%employees=("Tester" => "Joe",
            "Coder" => "Teddy",
            "Clerk" => "Tom",
           );
print "exists.\n" if exists $employees{"Tester"};
print "The Clerk exists.\n" if exists $employees{"Clerk"};
print "The Boss does not exist.\n" if not exists $employees{"Boss"};

   
    
    
    
  








Related examples in the same category

1.Determine if a particular key exists
2.If an entry exist
3.To tell if a given key name exists in a hash, you can use the exists operator.
4.Using 'if exists' to check the entry in hash