]> git.donarmstrong.com Git - infobot.git/blobdiff - scripts/dbm2mysql.pl
avoid reassigning to temp upon decode_utf8
[infobot.git] / scripts / dbm2mysql.pl
index 2a28679d714479605f2b589f0d14771aa425b221..a199cf799da385536784ea2696ea8e3bc3e9c170 100755 (executable)
@@ -10,9 +10,12 @@ require "src/Misc.pl";
 require "src/Files.pl";
 &loadDBModules();
 require "src/dbi.pl";
+
 package main;
 
-if (!scalar @ARGV) {
+# todo: main()
+
+if ( !scalar @ARGV ) {
     print "Usage: dbm2mysql <whatever dbm>\n";
     print "Example: dbm2mysql.pl apt\n";
     print "NOTE: suffix '-is' and '-extra' are used.\n";
@@ -24,46 +27,40 @@ my $key;
 my %db;
 
 # open dbm.
-if (dbmopen(%{ $dbm }, $dbfile, 0666)) {
-    &status("::: opening dbm file: $dbfile");
-} else {
+if ( !dbmopen( %db, $dbfile, 0666 ) ) {
     &ERROR("Failed open to dbm file ($dbfile).");
     exit 1;
 }
+&status("::: opening dbm file: $dbfile");
 
-### open all the data...
-&loadConfig("files/blootbot.config");
+# open all the data...
+&loadConfig("files/infobot.config");
 $dbname = $param{'DBName'};
-my $dbh_mysql = sqlOpenDB($param{'DBName'},
-       $param{'DBType'}, $param{'SQLUser'}, $param{'SQLPass'});
+my $dbh_mysql = sqlOpenDB(
+    $param{'DBName'},  $param{'DBType'},
+    $param{'SQLUser'}, $param{'SQLPass'}
+);
+print "DEBUG: scalar db == '" . scalar( keys %db ) . "'.\n";
 
-print "scalar db == '". scalar(keys %db) ."'.\n";
-
-my ($ndef, $i) = (1,1);
 my $factoid;
-foreach $factoid (keys %db) {
-    # blootbot dbm to sql support:
-    if (0) {
-       foreach (@DBM::extra_format) {
-#          my $val = &getFactInfo($key, $_, $db{$key});
-           if (!defined $val) {
-               $ndef++;
-               next;
-           }
-       }
-    } else {
-       # infobot dbm to blootbot sql support.
-        &sqlReplace("factoids", {
-               factoid_key     => $_,
-               factoid_value   => $db{$_},
-       } );
-    }
+my $ndef = 1;
+my $i    = 1;
+foreach $factoid ( keys %db ) {
+    &sqlReplace(
+        "factoids",
+        {
+            factoid_key   => $_,
+            factoid_value => $db{$_},
+        }
+    );
 
     $i++;
-    print "i=$i... " if ($i % 100 == 0);
-    print "ndef=$ndef... " if ($ndef % 1000 == 0);
+    print "i=$i... "       if ( $i % 100 == 0 );
+    print "ndef=$ndef... " if ( $ndef % 1000 == 0 );
 }
 
 print "Done.\n";
 &closeDB();
-dbmclose(%{ $dbm });
+dbmclose(%db);
+
+# vim:ts=4:sw=4:expandtab:tw=80