Next Lightweight Databases 36

Gappy Files

        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 ...


Next Copyright © 2003 M. J. Dominus