File Coverage

blib/lib/abbrev.pl
Criterion Covered Total %
statement 16 16 100.0
branch 2 2 100.0
condition 3 3 100.0
subroutine 1 1 100.0
pod n/a
total 22 22 100.0


line stmt bran cond sub pod time code
1             ;# Usage:
2             ;# %foo = ();
3             ;# &abbrev(*foo,LIST);
4             ;# ...
5             ;# $long = $foo{$short};
6              
7             #
8             # This library is no longer being maintained, and is included for backward
9             # compatibility with Perl 4 programs which may require it.
10             #
11             # In particular, this should not be used as an example of modern Perl
12             # programming techniques.
13             #
14             # Suggested alternative: Text::Abbrev
15             #
16              
17             package abbrev;
18              
19             sub main'abbrev {
20 1     1   648 local(*domain) = @_;
21 1         3 shift(@_);
22 1         4 @cmp = @_;
23 1         5 foreach $name (@_) {
24 6         28 @extra = split(//,$name);
25 6         17 $abbrev = shift(@extra);
26 6         13 $len = 1;
27 6         17 foreach $cmp (@cmp) {
28 36 100       105 next if $cmp eq $name;
29 30   100     156 while (@extra && substr($cmp,0,$len) eq $abbrev) {
30 7         18 $abbrev .= shift(@extra);
31 7         35 ++$len;
32             }
33             }
34 6         23 $domain{$abbrev} = $name;
35 6         19 while ($#extra >= 0) {
36 15         41 $abbrev .= shift(@extra);
37 15         70 $domain{$abbrev} = $name;
38             }
39             }
40             }
41              
42             1;