Hello all.
I am trying to remove unwanted commas from a CSV file. I am attempting to do this by changing any commas that are not contained in parenthesis to a colon character.
The following test program produces an unexpected result:
Outputs:
string before sub = "data","home 966-2815, cell 567-9832","data"
string after sub = "data","home 966-281:cell 567-9832","data"
I expected the only the comma after 964-2815 to be deleted but it also deleted the space following the comma. Why and how do I prevent that?
P.S.
The following substitutions also has the same output.
Facemann
I am trying to remove unwanted commas from a CSV file. I am attempting to do this by changing any commas that are not contained in parenthesis to a colon character.
The following test program produces an unexpected result:
Code:
my $string = '"data","home 966-2815, cell 567-9832","data"';
print "string before sub = $string\n";
$string =~ s/[^"],[^"]/:/g;
print "string after sub = $string\n";
Outputs:
string before sub = "data","home 966-2815, cell 567-9832","data"
string after sub = "data","home 966-281:cell 567-9832","data"
I expected the only the comma after 964-2815 to be deleted but it also deleted the space following the comma. Why and how do I prevent that?
P.S.
The following substitutions also has the same output.
Code:
s/[^"],{1}[^"]/:/g; ## and
s/[^"],{1}?[^"]/:/g;
Facemann