in reply to Substituting a comma only when it is preceded and followed by a bracket

my $l= ''; $s =~ s{([(,)])}{ my $n= ',' eq $1 && '(' eq $l ? ';' : $1; $l= $1 if ',' ne $1; $n }ge

- tye        

  • Comment on Re: Substituting a comma only when it is preceded and followed by a bracket (closure)
  • Download Code

Replies are listed 'Best First'.
Re^2: Substituting a comma only when it is preceded and followed by a bracket (closure)
by choroba (Cardinal) on Nov 02, 2011 at 17:26 UTC
    Does not work for nested parentheses *ducks*
    $s='aa, aaa, aaaa, aaa, (aaa, aaa, aaa, a), aaa, aaa, (aaa, aaa, (aaa, + aa), aaa, aaa), aaa, aaa';

      Ah, but I guess it beats BrowserUk's solution because it must be clearer that it doesn't work for nested parens else you wouldn't have left his un-replied-to for 22 minutes but replied to mine in 5 minutes when both fail for that same case. q-:

      - tye