Next | Lightweight Databases | 82 |
Searching will be fast:
sub find { my ($fh, $dbm, $key) = @_; my $offset = $dbm->{$key}; seek $fh, $offset, SEEK_SET; my $rec = <$fh>; return $rec; }
$fh is a filehandle on the (plain text) data file
$dbm is a reference to the DBM hash with the offset information
$key is the key we want to look up
We get the offset information from the DBM hash
Seek the filehandle to the right position in the text file
Read the right record instantly
Next | Copyright © 2003 M. J. Dominus |