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

for( 'sue,fred,x(mary,jane)', 'x(a,b),c(d,e,f),g,h,i(j,k)', 'a,b,cdef(g),h,i(j)' ) { print join' | ', m/( [^,(]+ \( [^)]+ \) | [^,]+ )(?:$|,)/gx; };; sue | fred | x(mary,jane) x(a,b) | c(d,e,f) | g | h | i(j,k) a | b | cdef(g) | h | i(j)

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: csv'ish string with parens that include commas
by Anonymous Monk on Dec 05, 2010 at 05:38 UTC
    m/\G( [^,()]* \( [^()]* \) | [^,()]+ )(?:,|$)/g­x;

      Is that intended as an improvement? What purpose does the \G serve?

        #perl -l for( 'sue,fred,x(mary,jane)', 'x(a,b),c(d,e,f),g,h,i(j,k)', 'a,b,cdef(g),h,i(j)', 'a,b,c(d(e,f,g)),h,i(j)' ) { print join' | ', m/( [^,(]+ \( [^)]+ \) | [^,]+ )(?:$|,)/gx; print join' | ', m/( [^,()]+ \( [^()]+ \) | [^,()]+ )(?:$|,)/gx; print join' | ', m/\G( [^,()]* \( [^()]* \) | [^,()]+ )(?:,|$)/gxc +; if( length != pos ) { warn "Invalid input: $_\n"; } print ''; };; ... a | b | c(d(e | f | g)) | h | i(j) a | b | e | f | h | i(j) a | b Invalid input: a,b,c(d(e,f,g)),h,i(j)