Next Lightweight Databases 38

Gappy Files

     ...
     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";
     }
     ...


Next Copyright © 2003 M. J. Dominus