in reply to CSV and regex mixups
If your trying to escape the embedded quotes before passing it to Text::CSV, then this might do the trick.
Note: I've added some extra embedded quotes to check that it doesn't escaped already escaped quotes and handles the edge cases at either end of the string. You'll need to throw a few more tests at this before using it in anger.
$s='"crosby","stills","nash",""and" ""sometimes"" "young""' # capture everything between a quote and a quote # follow by a comma or the end of string $s =~ s[ " (.*?) " ( , | $ ) ] { # Look for unescaped embedded quotes and escape them (my $t = $1) =~ s[ (?<!") " (?!") ][""]gx; # put back the outer quotes and the comma if there was one '"' . $t . '"' . ($2||''); }gex; print $s; "crosby","stills","nash","""and"" ""sometimes"" ""young"""
This assumes that $s would otherwise be parsed correctly by Text::CSV.
|
|---|