in reply to Replacing comas in a substring when it is between quotes

Another way is to use the third argument of split to attack the string from both ends to isolate the element in double quotes.

knoppix@Microknoppix:~$ perl -E ' > $l = q{w,ww,"a,bb,ccc,3 ,ee,",4}; > @flds = split m{,}, $l, 3; > push @flds, reverse > map { scalar reverse $_ } > split m{,}, reverse( pop @flds ), 2; > $flds[ 2 ] =~ s{,}{-}g; > $l = join q{,}, @flds; > say $l;' w,ww,"a-bb-ccc-3 -ee-",4 knoppix@Microknoppix:~$

I hope this is of interest.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Replacing comas in a substring when it is between quotes
by ZlR (Chaplain) on Mar 29, 2012 at 05:06 UTC
    yep ! got me to look up split and find was that this third argument does ! thanks !!