Annotation of db/prgsrc/eq/findequal.pl, revision 1.5
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:
35: if (checktable('equalto')) {die "The table equalto exists. You must delete it first!\n"};
36:
37: print "Creating equalto table...\n";
38:
39: mydo("CREATE TABLE equalto (
40: First INT UNSIGNED NOT NULL PRIMARY KEY, KEY FirstKey (First),
41: Second INT UNSIGNED NOT NULL, KEY SecondKey (Second)
42: )")
43:
44: or die "Can't create equalto table: $!\n";
45:
46:
1.5 ! roma7 47: if ((uc 'Á') ne 'á') {die "!Koi8-r locale not installed!\n"};
! 48: print "before getbase";
1.1 roma7 49:
50: getbase(QuestionId,Question);
51:
52:
1.5 ! roma7 53: print "after getbase";
1.1 roma7 54:
55: print "Loading questions...\n";
56:
1.4 roma7 57: if ((uc 'Á') ne 'á') {die "!Koi8-r locale not installed!\n"};
1.1 roma7 58:
59: while ((($id, $a) = getrow), $id)
60: {
61: if (!($id%1000)) {print "$id questions loaded...\n"}
62:
63: $a=~s/³£pPHXxAaBEe3KMoOT/åÅÒòîèÈáÁ÷åÅúëíÏïô/;
64: $a=uc $a;
65:
1.3 roma7 66: $a=~s/[^êãõëåîçûýúèÿüöäìïòðá÷ùæñþóíéôøâàÊÃÕËÅÎÇÛÝÚÈßÆÙ×ÁÐÒÏÌÄÖÜÑÞÓÍÉÔØÂÀ]//g;
1.1 roma7 67: $ar[$id]=$a;
68: $last=$id;
69: }
70:
71:
72:
73: print "Checking...\n";
74:
75: $cur=0;
76: $ar[0]="\0";
77: foreach $q (sort {($ar[$a] cmp $ar[$b])} 1..$last)
78: {
79: if ($ar[$q] eq $ar[$cur]) {$equal{$q}=$cur} else {$cur=$q}
80: }
81:
82: print scalar keys %equal, " pairs found\n";
83:
84: print("Updating the DB...\n");
85:
86: foreach $a (keys %equal)
87: {
88: mydo("INSERT INTO equalto (First,Second) VALUES ($a,$equal{$a})");
89: }
90:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>