To tell if a given key name exists in a hash, you can use the exists operator. : exists « Hash « Perl






To tell if a given key name exists in a hash, you can use the exists operator.

    

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


$hash{"Name"} = "A";
$hash{"Address"} = "B";
$hash{"City"} = "C";

if ( exists($hash{"City"} ) ) {
  print 'exists';
}

   
    
    
    
  








Related examples in the same category

1.Determine if a particular key exists
2.If an entry exist
3.The exists function returns true if a hash key (or array index) has been defined, and false if not.
4.Using 'if exists' to check the entry in hash