Perl Hash Key exists() Function

What is exists() Function in Perl in programming?


The exists() function is used to test whether a hash key is present.


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";
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!!".

Ask Questions

Ask Question