X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Ffixbadchars.pl;h=b7066a44e2a426630d7841bed7f692cf15810841;hb=45e51047c2df703229843193e49fb9829489170f;hp=2662993df0b4ed2b21a0e216189dfbb020f66622;hpb=cb81fea9939f349b36e3b5a0cdc0343a6b781da1;p=infobot.git diff --git a/scripts/fixbadchars.pl b/scripts/fixbadchars.pl old mode 100644 new mode 100755 index 2662993..b7066a4 --- a/scripts/fixbadchars.pl +++ b/scripts/fixbadchars.pl @@ -3,7 +3,7 @@ use DBI; my $dsn = "DBI:mysql:infobot:localhost"; -my $dbh = DBI->connect($dsn, "USERNAME", "PASSWORD"); +my $dbh = DBI->connect( $dsn, "USERNAME", "PASSWORD" ); my @factkey; my %factval; @@ -13,52 +13,60 @@ my $regex = '\\\\([\_\%])'; $query = "SELECT factoid_key,factoid_value from factoids"; my $sth = $dbh->prepare($query); $sth->execute; -while (my @row = $sth->fetchrow_array) { - if ($row[0] =~ /$regex/) { - push(@factkey,$row[0]); - } else { - $factval{$row[0]} = $row[1] if ($row[1] =~ /$regex/); +while ( my @row = $sth->fetchrow_array ) { + if ( $row[0] =~ /$regex/ ) { + push( @factkey, $row[0] ); + } + else { + $factval{ $row[0] } = $row[1] if ( $row[1] =~ /$regex/ ); } } $sth->finish; -print "scalar factkey => '". scalar(@factkey) ."'\n"; +print "scalar factkey => '" . scalar(@factkey) . "'\n"; foreach (@factkey) { print "factkey => '$_'.\n"; my $new = $_; $new =~ s/$regex/$1/g; - next if ($new eq $_); + next if ( $new eq $_ ); - $query = "SELECT factoid_key FROM factoids where factoid_key=". - $dbh->quote($new); + $query = + "SELECT factoid_key FROM factoids where factoid_key=" . $dbh->quote($new); my $sth = $dbh->prepare($query); $sth->execute; - if (scalar $sth->fetchrow_array) { # exist. - print "please remove $new or $_.\n"; - } else { # ! exist. - $sth->finish; + if ( scalar $sth->fetchrow_array ) { # exist. + print "please remove $new or $_.\n"; + } + else { # ! exist. + $sth->finish; - $query = "UPDATE factoids SET factoid_key=".$dbh->quote($new). - " WHERE factoid_key=".$dbh->quote($_); - my $sth = $dbh->prepare($query); - $sth->execute; - $sth->finish; + $query = + "UPDATE factoids SET factoid_key=" + . $dbh->quote($new) + . " WHERE factoid_key=" + . $dbh->quote($_); + my $sth = $dbh->prepare($query); + $sth->execute; + $sth->finish; } } -print "scalar factval => '". scalar(keys %factval) ."\n"; -foreach (keys %factval) { +print "scalar factval => '" . scalar( keys %factval ) . "\n"; +foreach ( keys %factval ) { print "factval => '$_'.\n"; my $fact = $_; - my $old = $factval{$_}; - my $new = $old; + my $old = $factval{$_}; + my $new = $old; $new =~ s/$regex/$1/g; - next if ($new eq $old); + next if ( $new eq $old ); - $query = "UPDATE factoids SET factoid_value=".$dbh->quote($new). - " WHERE factoid_key=".$dbh->quote($fact); + $query = + "UPDATE factoids SET factoid_value=" + . $dbh->quote($new) + . " WHERE factoid_key=" + . $dbh->quote($fact); my $sth = $dbh->prepare($query); $sth->execute; $sth->finish;