in reply to Complicated Search and Replace

print /^\s*\@MAC\((\w+)\s*,\s*(\w+)\s*,\s*(\w+)\s*,\s*(\d+)\s*\)\s*;\s +*$/ ? "$1 = (" . join('+',map "($2$_+$3$_)", 0..$4-1) . ");\n" : $_ while (<>);

Dave.

Replies are listed 'Best First'.
Re^2: Complicated Search and Replace
by ikegami (Patriarch) on Jun 27, 2005 at 18:34 UTC
    That doesn't even work for the examples provided by the OP. "What is important is getting the brackets in the right places", yet there are 4 pairs of brackets missing for n=8. Your solution only works for n=2 and n=4, and it's not even exact for n=2.
      whoops, wasn't reading OP closely enough.

      Dave.