Next Lightweight Databases 35

Gappy Files

        sub find {
          my ($fh, $key) = @_;
          seek $fh, 0, SEEK_SET;
          my $pos = 0;
          while (<$fh>) {
            chomp;
            next if /^\0*$/;  
            if (index($_, $key) == 0) {
              seek $fh, $pos, SEEK_SET;
              return $_;
            }
            $pos = tell $fh;
          }
          return;
        }


Next Copyright © 2003 M. J. Dominus