extract quoted strings with commas from csv
to extract from a csv file that may have the following format:
so that the resulting array contains
the following script worked:
a,b,c,"d,e,f",g,h,i,"j,k,l"
so that the resulting array contains
a
b
c
d,e,f
g
h
i
j,k,l
the following script worked:
open (F, $file);
while (<F>) {
while(/("[^"]+")/) {
$new = $orig = $1
$new =~ s/,/__comma__/g;
s/$orig/$new/;
}
@values = map {
s/__comma__/,/g;
"\'$_\'";
} split ',';

0 Comments:
Post a Comment
<< Home