Код: Выделить всё
#!/usr/bin/perl
use DBI;
$db_name = 's11_db';
# user from db
$db_user = 'root';
$db_pass = '';
$db_type = 'mysql';
$db_host = 'localhost';
$dbh = DBI->connect(
"DBI:$db_type:database=$db_name;host=$db_host",
$db_user,
$db_pass,
{ RaiseError => 1,
PrintError => 1 }
) || die $DBI::errstr;
my $sth = $dbh->prepare(
'select ID_TOPIC, body from messages where ID_BOARD = 18 AND ID_TOPIC != 168 limit 250'
);
$sth->execute();
my $rows;
push @{$rows}, $_ while $_ = $sth->fetchrow_hashref();
$sth->finish();
my $test;
foreach $_ ( @{$rows} ) {
$dbh->do(
qq{DELETE FROM messages
WHERE ID_TOPIC = ?
AND ID_TOPIC != 168
},
undef, $_->{ID_TOPIC}
);
# $_->{body} =~ s/...//;
# $_->{body} =~ s/</</;
# $_->{body} =~ s/>/>/;
# $_->{body} =~ s/"/""/;
$_->{body} =~ s/Цитата//;
$_->{body} =~ s/#3(.{1,6})//;
# $_->{body} =~ s/\[b\] \[/b\]//;
$_->{body} =~ s/#4(.{1,6})//;
$_->{body} =~ /(?:[http\:\/\/])(?:[\w\-]+\.)(\w+(?:[\.\-]))(?=[\.org.ru\.fff])/goi;
$_->{body} =~ s/http\:\/\/bash.org.ru\/quote\/(.{1,6})//;
$test .= " $_->{body} \n ====================================================== ";
next if ($_->{ID_TOPIC} == 168);
$dbh->do(
qq{INSERT INTO bad_topic (bad_topic,
true_topic)
VALUES (?,168)
},
undef, $_->{ID_TOPIC} );
}
my $sth = $dbh->prepare(
'UPDATE messages
SET
body = ?
WHERE ID_TOPIC = 168'
);
$sth->execute($test);
$sth->finish();