Next | Lightweight Databases | 36 |
sub modify { my ($fh, $rec) = @_; my $pos = tell $fh; chomp(my $oldrec = <$fh>); seek $fh, $pos, SEEK_SET;
if (length $oldrec == length $rec) { # easy case print $fh $rec;
} elsif (length $rec < length $oldrec) { my $shortfall = length($oldrec) - length($rec); my $fill = "\0" x ($shortfall-1); print $fh $rec, "\n", $fill;
... continued ...
In this case, the new record will fit in the old space
Say we're changing tchrist:A3Jye3/wLzQNs\n to tom:A3Jye3/wLzQNs\n
We actually change it to tom:A3Jye3/wLzQNs\n\0\0\0\n
This is the same length
find will ignore the \0\0\0\n 'gap'
Next | Copyright © 2003 M. J. Dominus |