Commit | Line | Data |
---|---|---|
0111154e Z |
1 | warn "Legacy library @{[(caller(0))[6]]} will be removed from the Perl core distribution in the next major release. Please install it from the CPAN distribution Perl4::CoreLibs. It is being used at @{[(caller)[1]]}, line @{[(caller)[2]]}.\n"; |
2 | ||
a687059c | 3 | ;# Usage: &look(*FILEHANDLE,$key,$dict,$fold) |
a6d71656 GS |
4 | # |
5 | # This library is no longer being maintained, and is included for backward | |
6 | # compatibility with Perl 4 programs which may require it. | |
dae35969 S |
7 | # This legacy library is deprecated and will be removed in a future |
8 | # release of perl. | |
a6d71656 GS |
9 | # |
10 | # In particular, this should not be used as an example of modern Perl | |
11 | # programming techniques. | |
dae35969 | 12 | |
a687059c LW |
13 | ;# Sets file position in FILEHANDLE to be first line greater than or equal |
14 | ;# (stringwise) to $key. Pass flags for dictionary order and case folding. | |
15 | ||
16 | sub look { | |
fe14fcc3 | 17 | local(*FH,$key,$dict,$fold) = @_; |
a687059c LW |
18 | local($max,$min,$mid,$_); |
19 | local($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, | |
20 | $blksize,$blocks) = stat(FH); | |
21 | $blksize = 8192 unless $blksize; | |
22 | $key =~ s/[^\w\s]//g if $dict; | |
55497cff | 23 | $key = lc $key if $fold; |
ac58e20f LW |
24 | $max = int($size / $blksize); |
25 | while ($max - $min > 1) { | |
26 | $mid = int(($max + $min) / 2); | |
27 | seek(FH,$mid * $blksize,0); | |
28 | $_ = <FH> if $mid; # probably a partial line | |
a687059c LW |
29 | $_ = <FH>; |
30 | chop; | |
31 | s/[^\w\s]//g if $dict; | |
55497cff | 32 | $_ = lc $_ if $fold; |
a687059c LW |
33 | if ($_ lt $key) { |
34 | $min = $mid; | |
35 | } | |
36 | else { | |
37 | $max = $mid; | |
38 | } | |
39 | } | |
ac58e20f | 40 | $min *= $blksize; |
a687059c | 41 | seek(FH,$min,0); |
ac58e20f | 42 | <FH> if $min; |
a687059c LW |
43 | while (<FH>) { |
44 | chop; | |
45 | s/[^\w\s]//g if $dict; | |
55497cff | 46 | $_ = lc $_ if $fold; |
a687059c LW |
47 | last if $_ ge $key; |
48 | $min = tell(FH); | |
49 | } | |
50 | seek(FH,$min,0); | |
51 | $min; | |
52 | } | |
53 | ||
54 | 1; |