Mega Code Archive

 
Categories / Perl / Hash
 

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'; }