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,$dict,$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 = lc $key if $fold;
14 $max = int($size / $blksize);
15 while ($max - $min > 1) {
16 $mid = int(($max + $min) / 2);
17 seek(FH,$mid * $blksize,0);
18 $_ = <FH> if $mid; # probably a partial line
21 s/[^\w\s]//g if $dict;
35 s/[^\w\s]//g if $dict;