Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

keys

Returns all keys of a hash, or the number of keys in scalar context.

In list context, pushes all keys of the hash onto the stack as individual string values. In scalar context, returns the number of key-value pairs. Accepts both %hash and $hashref (auto- dereferences). As a side effect, resets the hash’s internal iterator used by each.

Synopsis

my @k = keys %hash;
my $count = keys %hash;         # scalar context: number of keys
for my $key (keys %hash) { ... }

Implementation Notes

perl5: In scalar context, returns the number of keys. In list context, pushes all keys onto the stack.

See Also

PP runtime: keys | values, each, exists, delete