| Next | Lightweight Databases | 35 |
Searching first:
sub find {
my ($fh, $key) = @_;
seek $fh, 0, SEEK_SET;
my $pos = 0;
while (<$fh>) {
chomp;
next if /^\0*$/;
if (index($_, $key) == 0) {
seek $fh, $pos, SEEK_SET;
return $_;
}
$pos = tell $fh;
}
return;
}
This locates the first record that starts with $key and returns it
Also leaves $fh positioned at the start of that record
The key here is to ignore any line that is all NUL characters
These represent 'gaps' from which data has been removed
| Next | ![]() |
Copyright © 2003 M. J. Dominus |