File Coverage

blib/lib/look.pl
Criterion Covered Total %
statement 0 29 0.0
branch 0 22 0.0
condition n/a
subroutine 0 1 0.0
pod n/a
total 0 52 0.0


line stmt bran cond sub pod time code
1             ;# Usage: &look(*FILEHANDLE,$key,$dict,$fold)
2             #
3             # This library is no longer being maintained, and is included for backward
4             # compatibility with Perl 4 programs which may require it.
5             #
6             # In particular, this should not be used as an example of modern Perl
7             # programming techniques.
8             #
9             ;# Sets file position in FILEHANDLE to be first line greater than or equal
10             ;# (stringwise) to $key. Pass flags for dictionary order and case folding.
11              
12             sub look {
13 0     0     local(*FH,$key,$dict,$fold) = @_;
14 0           local($max,$min,$mid,$_);
15 0           local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,
16             $blksize,$blocks) = stat(FH);
17 0 0         $blksize = 8192 unless $blksize;
18 0 0         $key =~ s/[^\w\s]//g if $dict;
19 0 0         $key = lc $key if $fold;
20 0           $max = int($size / $blksize);
21 0           while ($max - $min > 1) {
22 0           $mid = int(($max + $min) / 2);
23 0           seek(FH,$mid * $blksize,0);
24 0 0         $_ = if $mid; # probably a partial line
25 0           $_ = ;
26 0           chop;
27 0 0         s/[^\w\s]//g if $dict;
28 0 0         $_ = lc $_ if $fold;
29 0 0         if ($_ lt $key) {
30 0           $min = $mid;
31             }
32             else {
33 0           $max = $mid;
34             }
35             }
36 0           $min *= $blksize;
37 0           seek(FH,$min,0);
38 0 0         if $min;
39 0           while () {
40 0           chop;
41 0 0         s/[^\w\s]//g if $dict;
42 0 0         $_ = lc $_ if $fold;
43 0 0         last if $_ ge $key;
44 0           $min = tell(FH);
45             }
46 0           seek(FH,$min,0);
47 0           $min;
48             }
49              
50             1;