Annotation of db/prgsrc/eq/findequal.pl, revision 1.10
1.1 roma7 1: #!perl
2:
3: #!/usr/local/bin/perl -w
4:
5: =head1 NAME
6:
7: findequal.pl - a script for filling the equalto tablee.
8:
9: =head1 SYNOPSIS
10:
11: findequal.pl
12:
13:
14: =head1 DESCRIPTION
15:
16: This script will create a table B<equalto>
17: in the B<chgk> database and fill it with pairs of
18: equal questions. If the tables exist, it will ask user whether
19: new table should be created.
20:
21: =head1 AUTHOR
22:
23: Roman Semizarov
24:
25: =cut
26:
27:
28: use DBI;
29: use locale;
30: use dbchgk;
31: use POSIX qw (locale_h);
32:
33: do "common.pl";
34:
1.8 roma7 35: my ($thislocale);
1.9 roma7 36: if ($^O =~ /win/i) {
1.8 roma7 37: $thislocale = "Russian_Russia.20866";
38: } else {
39: $thislocale = "ru_RU.KOI8-R";
40: }
41: POSIX::setlocale( &POSIX::LC_ALL, $thislocale );
42: if ((uc 'Á') ne 'á') {die "!Koi8-r locale not installed!\n"};
1.9 roma7 43:
1.8 roma7 44:
45:
1.7 roma7 46: if ((uc 'Á') ne 'á') {die "!Koi8-r locale not installed!\n"};
47:
48:
49:
1.1 roma7 50: if (checktable('equalto')) {die "The table equalto exists. You must delete it first!\n"};
51:
1.6 roma7 52: if ((uc 'Á') ne 'á') {die "!Koi8-r locale not installed!\n"};
53:
54:
55:
1.1 roma7 56: print "Creating equalto table...\n";
57:
58: mydo("CREATE TABLE equalto (
59: First INT UNSIGNED NOT NULL PRIMARY KEY, KEY FirstKey (First),
60: Second INT UNSIGNED NOT NULL, KEY SecondKey (Second)
61: )")
62:
63: or die "Can't create equalto table: $!\n";
64:
65:
1.5 roma7 66: if ((uc 'Á') ne 'á') {die "!Koi8-r locale not installed!\n"};
67: print "before getbase";
1.1 roma7 68:
69: getbase(QuestionId,Question);
70:
71:
1.5 roma7 72: print "after getbase";
1.1 roma7 73:
74: print "Loading questions...\n";
75:
1.4 roma7 76: if ((uc 'Á') ne 'á') {die "!Koi8-r locale not installed!\n"};
1.1 roma7 77:
78: while ((($id, $a) = getrow), $id)
79: {
80: if (!($id%1000)) {print "$id questions loaded...\n"}
81:
82: $a=~s/³£pPHXxAaBEe3KMoOT/åÅÒòîèÈáÁ÷åÅúëíÏïô/;
83: $a=uc $a;
84:
1.3 roma7 85: $a=~s/[^êãõëåîçûýúèÿüöäìïòðá÷ùæñþóíéôøâàÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀ]//g;
1.1 roma7 86: $ar[$id]=$a;
87: $last=$id;
88: }
89:
90:
91:
92: print "Checking...\n";
93:
94: $cur=0;
95: $ar[0]="\0";
96: foreach $q (sort {($ar[$a] cmp $ar[$b])} 1..$last)
97: {
98: if ($ar[$q] eq $ar[$cur]) {$equal{$q}=$cur} else {$cur=$q}
99: }
100:
101: print scalar keys %equal, " pairs found\n";
102:
103: print("Updating the DB...\n");
104:
105: foreach $a (keys %equal)
106: {
107: mydo("INSERT INTO equalto (First,Second) VALUES ($a,$equal{$a})");
108: }
109:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>