Next | Lightweight Databases | 37 |
sub modify {
... continued ...
} else { # New record is too big my $fill = "\0" x length($oldrec); print $fh $fill; seek $fh, 0, SEEK_END; # New record goes at the end print $fh $rec, "\n"; } }
Here the new record won't fit
We remove the old record entirely, and put the new one at the end
Say we're changing gnat:A51FSA8JrmV6M\n to torkington:A51FSA8JrmV6M\n
We replace gnat:A51FSA8JrmV6M\n with \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\n
We put torkington:A51FSA8JrmV6M\n at the end of the file
find will ignore the \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\n 'gap'
A sufficiently clever implementation might put something else into the gap later
Next | Copyright © 2003 M. J. Dominus |