-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnickhash.pl
48 lines (42 loc) · 933 Bytes
/
nickhash.pl
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
38
39
40
41
42
43
44
45
46
47
48
use MakeRegex 'make_regex';
open NICK, '<nicknames.txt' or die $!;
while(<NICK>)
{
chomp;
my($root,$nick,$akin)= split /\t/;
@alt= split /\W+/, $nick;
$match{$root}= [ map { push @{$root{$_}}, $root; $_ } @alt ];
$akin{$root}= [ split /\W/, $akin ];
}
for(keys %root)
{
if(@{$root{$_}} > 1)
{ $multi{$_}= delete $root{$_}; }
else
{ $root{$_}= $root{$_}->[0]; }
}
print "%root=\n(\n";
for(sort keys %root)
{
print " $_ => '$root{$_}',\n";
}
print ");\n\n";
print "%multi=\n(\n";
for(sort keys %multi)
{
print " $_ => [qw<@{$multi{$_}}>],\n";
}
print ");\n\n";
print "%match=\n(\n";
for(sort keys %match)
{
print " $_ => qr/^(".make_regex(map {s/E$/\$E/;$_} ($_,@{$match{$_}})).")\$/, # @{$match{$_}}\n";
}
print ");\n\n";
print "%akin=\n(\n";
for(sort keys %akin)
{
next unless @{$akin{$_}};
print " $_ => [qw<@{$akin{$_}}>],\n";
}
print ");\n\n";