#!/usr/bin/perl -w

# Usage: unsubsdel.pl <INFIL> <OUTFIL>
# Example:  unsubsdel.pl unsubsdel.txt unsubsdel.sql 
#
# David Harris, Version of 13 Jan 2006 16:06 PST

# ------------------------------------------------

# Check the number of arguments on the command line:
if ($#ARGV+1 != 2) {
  die "unsubsdel.pl needs <INFIL> <OUTFIL>  as arguments";
};
# Check existence of the textfile and email listing file:
(open INFIL, "<$ARGV[0]") or die "unsubsdel.pl INFIL file $ARGV[0] not found.\n";
(open OUTFIL, ">$ARGV[1]") or die "unsubsdel.pl OUTFIL file not made.\n";
#chomp $startsernums;

#Read through INFIL file:
while ($lineread = <INFIL>) {
  chomp $lineread;
  ($n1, $n2) = split(/\|/, $lineread);
    print OUTFIL
"DELETE personfacts
FROM personfacts, person 
WHERE person.email = \'$n2\'
AND person.personsernum = personfacts.personsernum ;
DELETE 
FROM `person`
WHERE email = '$n2';\n" ;
}
close OUTFIL;
close INFIL;
exit;