File:  [Local Repository] / db / prgsrc / eq / Attic / findequal.pl
Revision 1.6: download - view: text, annotated - select for diffs - revision graph
Fri May 18 22:48:49 2001 UTC (23 years, 1 month ago) by roma7
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

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

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