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

That looks pretty good, but it doesn't deal with multiple levels of parens. I think Text::Balanced is really the better solution.

-sam

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

Replies are listed 'Best First'.
Re: Re: Re: Splitting a comma-delimited string where a substring could countain commas
by dws (Chancellor) on May 03, 2002 at 21:12 UTC
    ... but it doesn't deal with multiple levels of parens.

    Coding now to deal with nested parens would be solving a problem that hasn't been presented. There might or might not be nested parens in the data. I'd wait for the "customer" to clarify their requirements before hitting this with a larger hammer. YMMV.

Re: Re: Re: Splitting a comma-delimited string where a substring could countain commas
by I0 (Priest) on May 03, 2002 at 21:53 UTC
    local $_ = "this, (that, those), these ((not enough, (nope)), never), +there"; (my $re=$_)=~s/((\()|(\))|.)/${[')','']}[!$3]\Q$1\E${['(','']}[!$2]/gs +; $re= join'|',map{quotemeta}eval{/$re/}; die $@ if $@ =~ /unmatched/; while( /((?:$re|[^,])*)/g ){ print "$1\n"; }