Perl | keys() Function Last Updated : 25 Jun, 2019 Comments Improve Suggest changes Like Article Like Report keys() function in Perl returns all the keys of the HASH as a list. Order of elements in the List need not to be same always, but, it matches to the order returned by values and each function. Syntax: keys(HASH) Parameter: HASH: Hash whose keys are to be printed Return: For scalar context, it returns the number of keys in the hash whereas for List context it returns a list of keys. Example 1: Perl #!/usr/bin/perl %hash = ('Ten' => 10, 'Eleven' => 11, 'Twelve' => 12, 'Thirteen' => 13); @values = values( %hash ); print("Values are ", join("-", @values), "\n"); @keys = keys( %hash ); print("Keys are ", join("-", @keys), "\n"); Output: Values are 11-12-13-10 Keys are Eleven-Twelve-Thirteen-Ten Example 2: perl #!/usr/bin/perl %hash = ('Geek' => 1, 'For' => 2, 'Geeks' => 3); @values = values( %hash ); print("Values are ", join("-", @values), "\n"); @keys = keys( %hash ); print("Keys are ", join("-", @keys), "\n"); Output: Values are 3-2-1 Keys are Geeks-For-Geek Comment More infoAdvertise with us Next Article Perl | keys() Function C Code_Mech Follow Improve Article Tags : Perl Perl-function Perl-Hash-Functions Similar Reads Perl | List Functions A list in Perl is a collection of scalar values. We can access the elements of a list using indexes. Index starts with 0 (0th index refers to the first element of the list). We use parenthesis and comma operators to construct a list. In Perl, scalar variables start with a $ symbol whereas list varia 4 min read Perl | ord() Function The ord() function is an inbuilt function in Perl that returns the ASCII value of the first character of a string. This function takes a character string as a parameter and returns the ASCII value of the first character of this string. Syntax: ord string Parameter: This function accepts a single par 1 min read Perl | chr() Function The chr() function in Perl returns a string representing a character whose Unicode code point is an integer. Syntax: chr(Num)Parameters: Num : It is an unicode integer value whose corresponding character is returned .Returns: a string representing a character whose Unicode code point is an integer. 1 min read Perl | each() Function This function returns a Two-element list consisting of the key and value pair for the next element of a hash when called in List context, so that you can iterate over it. Whereas it returns only the key for the next element of the hash when called in scalar context. Syntax: each MY_HASH Parameter: M 1 min read Perl | split() Function split() is a string function in Perl which is used to split or you can say to cut a string into smaller sections or pieces. There are different criteria to split a string, like on a single character, a regular expression(pattern), a group of characters or on undefined value etc.. The best thing abou 8 min read Perl | values() Function values() Function in Perl returns the list of all the values stored in a Hash. In a scalar context it returns the number of elements stored in the Hash. Note: Values returned from the value() Function may not always be in the same order. Syntax: values Hash Returns: list of values in the list contex 2 min read Perl | Useful Hash functions A hash is a set of key-value pairs. Perl stores elements of a hash such that it searches for the values based on its keys. Perl provides various functions to perform operations on Hashes, such as to return values of the hash, to delete elements from a hash, etc. Example: Perl #!/usr/bin/perl # Initi 2 min read Perl | delete() Function Delete() in Perl is used to delete the specified keys and their associated values from a hash, or the specified elements in the case of an array. This operation works only on individual elements or slices. Syntax: delete(LIST) Parameters: LIST which is to be deleted Returns: undef if the key does no 1 min read Perl | Useful Array functions In Perl, array is a special type of variable. The array is used to store the list of values and each object of the list is termed as an element. Elements can either be a number, string, or any type of scalar data including another variable. Array in Perl provides various inbuilt functions to perform 2 min read Perl | Useful String functions A string in Perl is a scalar variable and start with a ($) sign and it can contain alphabets, numbers, special characters. The string can consist of a single word, a group of words or a multi-line paragraph. The String is defined by the user within a single quote (â) or double quote (â). Perl provid 3 min read Like