Perl each Function

Advertisements


Description

This function when called in list context, returns a 2-element list consisting of the key and value for the next element of a hash, so that you can iterate over it. When called in scalar context, returns only the key for the next element in the hash.

Syntax

Following is the simple syntax for this function:

each HASH

Return Value

This function when called in list context, returns a 2-element list consisting of the key and value for the next element of a hash, so that you can iterate over it. It returns only the key for the next element in the hash when called in scalar context.

Example

Following is the example code showing its basic usage, this will print out all environment variables.:


When above code is executed, it produced following result:




Advertisements
Advertisements