#!/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 != 4) {
  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]; $startnum2 = $ARGV[3];
chomp $startnum;      chomp $startnum2;
$i = 0;               $j=0;
#Read through TXTLIST file:
while ($lineread = <TXTLIST>) {
  chomp $lineread;
  $col1 = $startnum+$i;    $col2 = $startnum2+$j;
  print SQLOUT "$col1\|$col2\|'isacadlib'\|NULL\|NULL\n" ;
  $i++;   $j++;
}

close SQLOUT;
close TXTLIST;
exit;