Quickly, I might not have caught everything
'g' modifier in an if is almost always wrong. It is wrong here.
$2 in s/.../$2/ refers to the second capture in ..., not some earlier capture by some other match or substitution operator.
The search expression appears to be text, not a regexe, but you use it as a regexp.
Using $_ in $_ =~ s/$1/$2/g; and print $_; defies the purpose of using $_.
for my $line (@lines) { for my $replace (@replaces) { my ($s,$r) = $replace =~ /\\replace\t(.+?)\t(.+?)\n/ or next; $line =~ s/\Q$s\E/$r/g; } print $line; }
Update: Actually, that's a bad approach since you have to keep recompiling regexps. Reverse the nesting of your loops:
for my $replace (@replaces) { my ($s,$r) = $replace =~ /\\replace\t(.+?)\t(.+?)\n/ or next; s/\Q$s\E/$r/g for @lines; } print @lines;
Update: Woops, I was still using $2. Switched to $r.
In reply to Re: Help in using two arrays
by ikegami
in thread Help in using two arrays
by rsriram
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |