8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(look);
13 Search::Dict, look - search for key in dictionary file
18 look *FILEHANDLE, $key, $dict, $fold;
22 Sets file position in FILEHANDLE to be first line greater than or equal
23 (stringwise) to I<$key>. Returns the new file position, or -1 if an error
26 The flags specify dictionary order and case folding:
28 If I<$dict> is true, search by dictionary order (ignore anything but word
29 characters and whitespace).
31 If I<$fold> is true, ignore case.
36 my($fh,$key,$dict,$fold) = @_;
40 my($size, $blksize) = @stat[7,11];
42 $key =~ s/[^\w\s]//g if $dict;
43 $key = lc $key if $fold;
44 my($min, $max, $mid) = (0, int($size / $blksize));
45 while ($max - $min > 1) {
46 $mid = int(($max + $min) / 2);
47 seek($fh, $mid * $blksize, 0)
49 <$fh> if $mid; # probably a partial line
52 s/[^\w\s]//g if $dict;
54 if (defined($_) && $_ lt $key) {
70 s/[^\w\s]//g if $dict;