Managing DBM Files
The Each Function
- The each() function steps through key-value pairs
of an associative array
- This is useful for walking through large DBM files
- Here's a SMALL example just to demonstrate the each() function
%myHash = ( "a", "Ape", "b", "Bat", "c", "Cat" );
while ( ($key, $value) = each( %myHash ) )
{
print "$key = $value\n";
}
- Assigning to the array or calling keys()
or values() will reset each() back to the
first key-value pair
- Don't add/delete elements in a loop because each() will
get confused!