blob: 77370d37c3947eaf31d3f3f06069044848e2301b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package Text::Abbrev;
require 5.000;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(abbrev);
# Usage:
# &abbrev(*foo,LIST);
# ...
# $long = $foo{$short};
sub abbrev {
local(*domain) = shift;
@cmp = @_;
%domain = ();
foreach $name (@_) {
@extra = split(//,$name);
$abbrev = shift(@extra);
$len = 1;
foreach $cmp (@cmp) {
next if $cmp eq $name;
while (substr($cmp,0,$len) eq $abbrev) {
$abbrev .= shift(@extra);
++$len;
}
}
$domain{$abbrev} = $name;
while (@extra) {
$abbrev .= shift(@extra);
$domain{$abbrev} = $name;
}
}
}
1;
|