In Perl, the keys()
function is used to return all the keys of a hash as a list.
keys(hash)
This function takes the parameter hash
. This is the hash we want to get the keys of.
It returns a list of keys.
# create hashes%hash1 = ('One' => 1,'Two' => 2,'Third' => 3,'Fourth' => 4);%hash2 = ('Edpresso' => 1,'Is' => 2,'Awesome' => 3);# get keys@keys1 = keys(%hash1);@keys2 = keys(%hash2);# print keysprint("Keys are ", join("-", @keys1), "\n");print("Keys are ", join("-", @keys2), "\n");
keys()
function to get the keys of the hashes.join()
method to separate the keys of the hashes that the key()
function returned.