| Next | Lightweight Databases | 38 |
A variation: fill the gaps with newlines instead of NULs:
...
if (length $oldrec == length $rec) {
# easy case
print $fh $rec;
} elsif (length $rec < length $oldrec) {
my $shortfall = length($oldrec) - length($rec);
my $fill = "\n" x $shortfall;
print $fh $rec, "\n", $fill;
} else { # New record is too big
my $fill = "\n" x length($oldrec);
print $fh $fill;
seek $fh, 0, SEEK_END; # New record goes at the end
print $fh $rec, "\n";
}
...
Then have find ignore blank lines
See mip2.pl in the handout
| Next | ![]() |
Copyright © 2003 M. J. Dominus |