#!/usr/bin/perl -w

# Usage: unsub2sql.pl <txtlist> <sqlout> <startnum>
#
# Example:  unsub2sql.pl txtlist.txt sqlout.txt 25861
#
# David Harris, Version of 3 Jan 2006 23:10 GMT

# ------------------------------------------------

# Check the number of arguments on the command line:
if ($#ARGV+1 != 3) {
  die "unsub2sql.pl needs <txtlist> <sqlout> <start-number> as arguments";
};
# Check existence of the textfile and email listing file:
(open TXTLIST, "<$ARGV[0]") or die "unsub2sql.pl txtlist file $ARGV[0] not found.\n";
(open SQLOUT, ">$ARGV[1]") or die "unsub2sql.pl SQL file not made.\n";
$startnum = $ARGV[2]; 
chomp $startnum; 
$i = 0;
#Read through TXTLIST file:
while ($email = <TXTLIST>) {
  chomp $email;
  $personsernum = $startnum+$i; 
  print SQLOUT "$personsernum\|$email\n" ;
  $i++;
}

close SQLOUT;
close TXTLIST;
exit;