each
Returns the next key-value pair from a hash’s internal iterator.
Advances the hash’s internal iterator and returns the next entry.
In list context, pushes a (key, value) pair. In scalar context,
returns only the key. When the iterator is exhausted, returns an
empty list (list context) or undef (scalar context), and the
iterator resets automatically for the next traversal.
Note: keys and values reset the same internal iterator, so
calling them during an each loop will restart iteration.
Synopsis
while (my ($k, $v) = each %hash) { ... }
while (my $k = each %hash) { ... } # scalar context: key only