Perl Hash Key exists() Function
What is exists() Function in Perl in programming?
Explanation
The exists() function is used to test whether a hash key is present.
Syntax:
exists hash;
Example :
#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
%emp = ('empno' => '12422' , 'empname' => 'Kate Anderson',
'empph' => '9167552148', 'empcode' => 'ADS212');
if (exists $emp{'empcode'})
{
print "Employee Code Exists!!n";
}
else
{
print "Employee Code Missing??n";
}
Result :
Employee Code Exists!!
In the above example using the exists() function the key "empcode" is checked in the hash "emp", as it is present it displays "Employee Code Exists!!".