in reply to Replacing comas in a substring when it is between quotes
Using Text::CSV seems like a more likely way to get it right on the first try. But your idea isn't hard to do:
s{(".*?")}{ my $s = $1; $s =~ s/,/-/g; $s }ge
You can also replace the regex with something that handles escapes.
Just for variety, here is another approach:
my $in = 0; s{(")|,}{ if($1){ $in= !$in; $1 }elsif($in){ '-' }else{ ',' } }ge
- tye
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Replacing commas in a substring when it is between quotes (2 ways)
by ZlR (Chaplain) on Mar 29, 2012 at 04:59 UTC |