Well, there are still pieces of your script missing, so I'm not sure I've captured all of the functionality, but try this...

#!/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<Br>\n"; if ($address ne $bademail) { push @goodmails,$address; } } if (scalar(@goodmails)) { my $newlist=join('~~~',@goodmails); $dbh->do("UPDATE $alertstable SET email='$newlist' WHERE t +ype='$item' and alerttype='$alertype';") || die $dbh->errstr; print "Updated $ID<Br>\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); }

You'll need to fix up the connect code to reflect your username and password for the database, and it was not clear what $alertable ever got set to, so make sure it is right.

Scott


In reply to Re: Comparing 2 databases by helphand
in thread Comparing 2 databases by htmanning

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.