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   406 local(*domain) = @_;
21 1         2 shift(@_);
22 1         2 @cmp = @_;
23 1         2 foreach $name (@_) {
24 6         14 @extra = split(//,$name);
25 6         6 $abbrev = shift(@extra);
26 6         7 $len = 1;
27 6         7 foreach $cmp (@cmp) {
28 36 100       49 next if $cmp eq $name;
29 30   100     67 while (@extra && substr($cmp,0,$len) eq $abbrev) {
30 7         8 $abbrev .= shift(@extra);
31 7         16 ++$len;
32             }
33             }
34 6         10 $domain{$abbrev} = $name;
35 6         10 while ($#extra >= 0) {
36 15         18 $abbrev .= shift(@extra);
37 15         28 $domain{$abbrev} = $name;
38             }
39             }
40             }
41              
42             1;