while {}
for this reason.)
Entries are returned in an apparently random order. When the hash is entirely read, a null array is returned in list context (which when assigned produces a
FALSE (0) value), and
undef is returned in a scalar context. The next call to each
after
that will start iterating again. There is a single iterator for each hash,
shared by all each,
keys,
and values
function calls in the program; it can be reset by reading all the elements
from the hash, or by evaluating keys HASH
or
values HASH
. If you add or delete elements of a hash while you're iterating over it,
you may get entries skipped or duplicated, so don't.
The following prints out your environment like the printenv
program, only in a different order:
while (($key,$value) = each %ENV) { print "$key=$value\n"; }
See also keys
and values.