[Kc] one way to handle commas in quotes strings in CSV files

David Nicol davidnicol at gmail.com
Mon May 2 14:23:41 PDT 2011


one way to handle commas in quotes strings in CSV files -- of course
if your data has angle brackets in it, or form feeds, you'll need a
different three characters.

while (<>){

     while (/"/){
        m/[<>\f]/ and die "ANGLE BRACKET OR FF IN INPUT! [$_]";
        s/"/</; s/"/>/ or die "unpaired quotes in [$_]";
        1 while s/<(.*?),(.*?)>/<$1\f$2>/;
        s/[<>]//g;
     };
     my @line = split ',',$_;
     s/\f/,/g for @line;

     ...


};


-- 
"During his first performance of the song he received one of the
highest honors you can achieve in New York’s underground rap scene:
audience members touched his sneakers after a few of the more
particularly tight lines."  -- Cal Newport


More information about the kc mailing list