in reply to Escape the special characters while substitution
$ perl -wle'use strict; my $str2 = "@cce$$ag@!n"; print $str2;' Global symbol "@cce" requires explicit package name at -e line 1. Global symbol "$ag" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors. $ perl -wle'use strict; my $str2 = "\@cce\$\$ag\@!n"; print $str2;' @cce$$ag@!n
Now that the variables contain what you want them to contain, you still need to convert $str1 and $abc1 into a regexp pattern. quotemeta can be used to do that.
my $str1_pat = quotemeta($str1); $str1 =~ s/$str1_pat/$str2/; - or - $str1 =~ s/\Q$str1\E/$str2/; # Same thing.
But the fact that s/// is used at all is very fishy. s/// should be needed to change a password!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Escape the special characters while substitution
by MidLifeXis (Monsignor) on Apr 24, 2009 at 19:12 UTC | |
|
Re^2: Escape the special characters while substitution
by bichonfrise74 (Vicar) on Apr 24, 2009 at 19:45 UTC |