1 ;# Usage: &look(*FILEHANDLE,$key,$dict,$fold)
3 ;# Sets file position in FILEHANDLE to be first line greater than or equal
4 ;# (stringwise) to $key. Pass flags for dictionary order and case folding.
7 local(*FH,$key,$fold) = @_;
8 local($max,$min,$mid,$_);
9 local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
10 $blksize,$blocks) = stat(FH);
11 $blksize = 8192 unless $blksize;
12 $key =~ s/[^\w\s]//g if $dict;
13 $key =~ y/A-Z/a-z/ if $fold;
14 $max = $size + $blksize - 1;
15 $max -= $size % $blksize;
16 while ($max - $min > $blksize) {
17 $mid = ($max + $min) / 2;
18 die "look: internal error" if $mid % $blksize;
20 $_ = <FH>; # probably a partial line
23 s/[^\w\s]//g if $dict;
35 s/[^\w\s]//g if $dict;