in reply to Re: Splitting a comma-delimited string where a substring could countain commas
in thread Splitting a comma-delimited string where a substring could contain commas

Excluding embeded paranthesis (which the poster did not mentioned), tr%()%""% would solve the grouping problem for CSV.

--
perl -pew "s/\b;([mnst])/'$1/g"

  • Comment on Re: Re: Splitting a comma-delimited string where a substring could countain commas
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Splitting a comma-delimited string where a substring could countain commas
by mrbbking (Hermit) on May 05, 2002 at 00:39 UTC
    If the whole field were in parenthesis, you're right, that would work.

    But the value is this:
    , these (not enough, nope, never),
    ...not this...
    , (these not enough, nope, never),

    Text::CSV_XS chokes if you replace the parens with your tr/// suggestion. CSV requires that either the whole field or none of the field be quoted - you can't quote part of a field.

      Good call. A little massaging would overcome that, but then that puts us in the realm of s/// and others have already posted better solutions using that.

      --
      perl -pew "s/\b;([mnst])/'$1/g"