If you wish to iterate through an entire hash, you can use the
values and keys functions, but a more
elegant and efficient approach is to use the each(%Hashname)
function.
Every time each is called, the next succesive two
element key and value pair is returned.
When all values have been returned, each will
return an empty list. This also resets the each
operator to start back at the beginning of the hash for the next
invocation.
An assignment of a new value to the entire hash will
reset the each function to the beginning of the hash.
Adding or deleting elements to the hash within a loop that is
iterating via each is at best confusing, and is likely
to break something.
Example:
for ($aScalar=0; $aScalar < 10; $aScalar++)
{
$aHash{"Key$aScalar"} = "Value$aScalar";
}
while ( ($Key, $Value) = each(%aHash) )
{
print "Hash with Key=$Key is Value=$Value\n";
}
Using each in a scalar context returns each
successive key.