in reply to Replace multiple strings in a string
Here is the fixed version:
#!/usr/bin/perl use warnings; use strict; my $a = "aRep"; my $b = "bRep"; my $c = "cRep"; my @Search = ("?a?", "?b?", "?c?"); my @Replace = ($a, $b, $c); my $string = '?a? ?b? ?c?'; print "old string: $string\n"; for (my $i = 0; $i < $#Search + 1; $i++) { $string =~ s/\Q$Search[$i]/$Replace[$i]/g; } print "new string: $string\n"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Replace multiple strings in a string
by Axlex (Initiate) on May 07, 2014 at 15:34 UTC |