ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
17.3 Using a DBM HashAfter the database is opened, accesses to the DBM hash are mapped into references to the database. Changing or adding a value in the hash causes the corresponding entries to be immediately written into the disk files. For example, once $FRED{"fred"} = "bedrock"; # create (or update) an element delete $FRED{"barney"}; # remove an element of the database foreach $key (keys %FRED) { # step through all values print "$key has value of $FRED{$key}\n"; } That last loop has to scan through the entire disk file twice: once to access the keys, and a second time to look up the values from the keys. If you are scanning through a DBM hash, it's generally more disk-efficient to use the while (($key, $value) = each(%FRED)) { print "$key has value of $value\n"; } |