luupski has asked for the wisdom of the Perl Monks concerning the following question:
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: remove a comma
by stevieb (Canon) on Jun 20, 2018 at 18:02 UTC | |
|
Re: remove a comma
by golux (Chaplain) on Jun 21, 2018 at 13:20 UTC | |
by luupski (Initiate) on Jun 21, 2018 at 22:09 UTC | |
by golux (Chaplain) on Jun 22, 2018 at 00:38 UTC | |
by luupski (Initiate) on Jun 21, 2018 at 20:06 UTC | |
|
Re: remove a comma
by poj (Abbot) on Jun 20, 2018 at 19:33 UTC | |
|
Re: remove a comma
by mr_ron (Deacon) on Jun 20, 2018 at 22:30 UTC | |
by luupski (Initiate) on Jun 23, 2018 at 05:21 UTC | |
|
Re: remove a comma
by luupski (Initiate) on Jun 20, 2018 at 20:25 UTC |