in reply to csv'ish string with parens that include commas

FWIW, that is bogus csv

I would preprocess with

my $csv = Text::CSV->new({ qw! allow_loose_escapes 1 allow_loose_quotes 1 ! }); ... s/x\(([^\(\)]+)\)/"$1"/g; $csv->parse($_);
Seems to work
$ perl -MText::CSV -e" $t = Text::CSV->new({qw! auto_diag 1 allow_loos +e_escapes 1 allow_loose_quotes 1 ! }); $_ = q!sue,fred,x(mary,jane)!; + s/x\(([^\(\)]+)\)/\x22$1\x22/g; warn $_; warn $t->parse( $_ ); warn$ +_ for $t->fields" sue,fred,"mary,jane" at -e line 1. 1 at -e line 1. sue at -e line 1. fred at -e line 1. mary,jane at -e line 1.

Replies are listed 'Best First'.
Re^2: csv with parens that include commas
by ascetic (Novice) on Dec 05, 2010 at 01:37 UTC

    I want the third item to be the string

    x(mary,jane)

    i.e. mary and jane are two args of function x which I am going to resolve by processing the third item later on

    P.S. Although this may not meet the technical definition of "csv" it was useful in the title.

      Yes, and? You want to treat something that is not CSV as CSV. Thats a no-go situation.
      A reply falls below the community's threshold of quality. You may see it by logging in.