Next | Lightweight Databases | 83 |
Where did the offset information come from?
sub make_index { my ($fh, $dbm, $key_function) = @_; seek $fh, 0, SEEK_SET; %$dbm = (); my $pos = 0; while (<$fh>) { chomp; my $key = $key_function->($_); $dbm->{$key} = $pos; $pos = tell $fh; } }
$fh and $dbm are as before
$key_function takes a record from the file and says what the key should be
If the DBM eats the index, your homework is still intact
Next | Copyright © 2003 M. J. Dominus |