ZlR has asked for the wisdom of the Perl Monks concerning the following question:
Here i am once again with another too hard for me problem ! I was given numerous csv files, and they use a comma as a field separator. To my surprise, some fields contain commas as a value. Since I intend to split on comas this kinda wrecks it all up. Those fields get enclosed in quotes, so one can see that the comas inside are values, and not a field separator.
Maybe I could use a csv module, but that's too easy ! But seriously, it got me thinking on this regexp problem :
# a 4 field coma separated csv line $l = 'w,ww,"a,bb,ccc,3 ,ee,",4' ;
How can i turn it into :
# a 4 field coma splitable csv line 'w,ww,"a-bb-ccc-3 -ee-",4' ;
I do not have a single idea so far ...
I guess it would be like running a regexp ( s/,/-/g ) on a match ( m/"(.*)"/ ), but i don't know how to do that.
Anyone knows how ? Thanks !
|
---|