I have the following list in a notepad file called CUSTOMER.txt
--- this is CUSTOMER.txt (input) ---
0001 20000001 john CA
0002 30000002 neill WI
0003 40000003 joe GA
0004 50000004 will IL
0005 60000005 mike IN
0006 70000006 bill AK
I feed this into the script and get the following output which is placed in the CUSTOMER_NEW.txt file
All good for except 1 thing.
I want the last ' , ' (comma)to be removed before the closing bracket.
Tried several things after googling, but no success
So i was wandering if anybody has an idea how to add to the code given that will remove the last ' , '
--- this is CUSTOMER_NEW.txt (output) ---
SELECT CUSTOMERID, ORDERID, CUSTOMERNAME, CUSTOMERLOCATION
FROM DB.CUSTOMER_DATA
WHERE (CUSTOMERID, ORDERID, CUSTOMERNAME, CUSTOMERLOCATION) IN (
(0001,20000001,john,CA),
(0002,30000002,neill,WI),
(0003,40000003,joe,GA),
(0004,50000004,will,IL),
(0005,60000005,mike,IN),
(0006,70000006,bill,AK),
)
sub customer {system ("notepad ./CUSTOMER.txt"); $dir="./"; $custom=$dir."CUSTOMER.txt"; $dir="./CUSTOMER_DIR/"; $ofile=$dir."CUSTOMER_NEW.txt"; open (IN,"$custom") || die "Cannot open CUSTOMER.txt!!!\n"; open (OUT,">$ofile") || die "Cannot open CUSTOMER_NEW.txt!!!\n"; print OUT "SELECT CUSTOMERID, ORDERID, CUSTOMERNAME, CUSTOMERLOCATION FROM DB.CUSTOMER_DATA WHERE (CUSTOMERID, ORDERID, CUSTOMERNAME, CUSTOMERLOCATION) IN (\n"; @CUST=<IN>;close IN; foreach $infile (@CUST){ chomp($infile); $i=0; @a=split(/\|/,$infile); @BAGO=$a[$i]; foreach $infile1 (@BAGO){ @b=split(/\s+/,$infile1); print OUT "($b[0],$b[1],$b[2],$b[3])\,\n"; $i++;}} print OUT ")\n"; system ("notepad ./CUSTOMER_DIR/CUSTOMER_NEW.txt"); close OUT; goto START; }
In reply to remove a comma by luupski
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |