Perl Hash Indices List, keys() Function

What is keys() Function in Perl programming?

Explanation

The keys() function is used to retrieve list of indices from a hash.

Syntax:


keys hash;

Example :


#! C:programfilesperlbinperl
print "content-type: text/htmlnn";
%emp = ('empno' => '12422' , 'empname' => 'Kate Anderson',
'empph' => '9167552148', 'empcode' => 'ADS212');
foreach $key (keys %emp)
{
print "$keyn";
}
Result :

empcode empname empph empno

In the above example using the keys() function all the keys of the hash "emp" is displayed using a for each loop.

Ask Questions

Ask Question