[Chicago-talk] Removing Characters

Shlomi Fish shlomif at iglu.org.il
Mon Oct 22 08:27:11 PDT 2007


On Monday 22 October 2007, tiger peng wrote:
> Hello,
>
> There must be better way for removing the double quote in a CSV file
> optionally quoted by double quote. What I did as below is ugly and not
> reliable. Could anyone provide one beautify line?
>
>   $delimiter=chr(0227);
>   s/^"/$delimiter/g;
>   s/,"/,$delimiter/g;
>   s/"$/$delimiter/g;
>   s/",/$delimiter,/g;
>   s/"//g;
>   s/$delimiter/"/g;

Is there any reason you're not using Text::CSV_XS to parse the CSV?

http://search.cpan.org/dist/Text-CSV_XS/

Otherwise, you may wish to process the line incrementally using \G and /g.

Regards,

	Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://www.shlomifish.org/

If it's not in my E-mail it doesn't happen. And if my E-mail is saying
one thing, and everything else says something else - E-mail will conquer.
    -- An Israeli Linuxer


More information about the Chicago-talk mailing list