Annotation of db/prgsrc/findequal.pl, revision 1.2

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>