#!/usr/bin/perl use strict; use warnings; use DBI; my $alertstable = $ARGV[0] || 'alertstable'; my $dbh = DBI->connect("DBI:mysql:database=dbname;host=sqlhost", 'username','password', {'RaiseError'=>1}); my $sth=&Do_SQL("Select * from bademails ORDER BY ID DESC"); while (my $pointer = $sth->fetchrow_hashref) { my $bademail = $pointer->{'email'}; my $sth2=&Do_SQL2("Select * from $alertstable where email LIKE '%$bademail%'"); while (my $pointer2 = $sth2->fetchrow_hashref) { my $item = $pointer2->{'type'}; my $alertype = $pointer2->{'alertype'}; my $emaillist = $pointer2->{'email'}; my $ID = $pointer2->{'ID'}; my @emails = split /~~~/,$emaillist; my @goodmails = (); foreach my $address (@emails) { print "$ID
\n"; if ($address ne $bademail) { push @goodmails,$address; } } if (scalar(@goodmails)) { my $newlist=join('~~~',@goodmails); $dbh->do("UPDATE $alertstable SET email='$newlist' WHERE type='$item' and alerttype='$alertype';") || die $dbh->errstr; print "Updated $ID
\n"; } } } # end while $dbh->disconnect; sub Do_SQL{ my ($SQL)=@_; my $sth; eval { $sth = $dbh->prepare($SQL); }; # check for errors if($@){ $dbh->disconnect; print "Content-type: text/html\n\n"; print "An ERROR occurred! $@\n"; exit; } else { $sth->execute; } return ($sth); }