#!/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 22:10 GMT

# ------------------------------------------------

# Check the number of arguments on the command line:
if ($#ARGV+1 != 3) {
  die "unsub2sql.pl needs <txtlist> <sqlout> <database table name> 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 ($lineread = <TXTLIST>) {
  chomp $lineread;
  $col1 = $startnum+$i; 
  print SQLOUT "$col1\|$lineread\n" ;
  $i++;
}

close SQLOUT;
close TXTLIST;
exit;