in reply to Complicated Search and Replace
What follows is a recursive solution. The expressions are paired, then the pairs are paired, then the paired pairs are paired, etc. until only one expression is left.
use strict; use warnings; my $command = '@MAC(output,X,Y,8);'; my ($fields) = $command =~ /\@MAC\((.*?)\)/; my ($output, $var1, $var2, $size) = split(/\s*,\s*/, $fields); my @data = map { "$var1$_*$var2$_"} (0 .. $size-1); while (@data > 1) { my @compressed; push @compressed, sprintf("(%s)+(%s)", shift(@data), shift(@data)) while @data; @data = @compressed; } print("$output = $data[0];\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Complicated Search and Replace
by gantlord (Initiate) on Jun 27, 2005 at 18:43 UTC | |
by ikegami (Patriarch) on Jun 27, 2005 at 18:48 UTC |