in reply to Trying to find missing closing quotes in CSV

Alternatively, you could be looking for lines with an odd number of quotes:

use strict; use warnings; while(<DATA>){ print if tr/"/"/ % 2 } __DATA__ 1,2,3 "1",2,3 1,2,"3

Replies are listed 'Best First'.
Re^2: Trying to find missing closing quotes in CSV
by Tux (Canon) on Sep 17, 2013 at 09:00 UTC

    Bad idea. In perfectly correct CSV, it is possible to have odd number of " perl line in many different ways. This is valid CSV (all lines with " have an odd number of "):

    $ cat test.csv 1,"2,","3"04" 2,"newline there -> and more text for row 2",There 3,,Bah $ csv-check test.csv Checked test.csv with csv-check 1.5 using Text::CSV_XS 1.01 OK: rows: 3, columns: 3 sep = <,>, quo = <">, bin = <1>, eol = <"\n"> $

    Parsing CSV with regular expressions and/or on perl default readline method is a dangerous path to walk.


    Enjoy, Have FUN! H.Merijn