411 REFERENCE · Wikibooks
Perl Programming/Keywords/keys
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Perl join kill Keywords
The keys keyword
The keys command returns all the keys the HASH has in an apparent random order, when called in list context. In Perl 5.12.0 or later, the indices of an ARRAY are returned.
As a side effect, keys resets the internal iterator of the ARRAY or HASH (see each). Calling it in void context resets the iterator with no other overhead.
Syntax
keys HASH
keys ARRAY
keys EXPRESSION
Examples
%hash = (foo => 11, bar => 22, baz => 33);
print "keys, values\n";
@keys = keys %hash;
@values = values %hash;
while (@keys) {
print pop(@keys), ' => ', pop(@values), "\n";
} results in keys, values
foo => 11
baz => 33
bar => 22
See also
each
values
Perl join kill Keywords