
1arryb
User
Mar 16, 2009, 10:44 AM
Post #2 of 3
(320 views)
|
Hi aiyer, You never initialize $mystring in your code snippet. Consequently,
$mystring =~ s/$mytest1/$myrep1/g; Will always fail. Not sure why you want the backslashes, but this:
#!/usr/bin/perl use strict; use warnings; my $mytest1 = "\\\\abc"; # escape backslash twice: Once for the definition and once for the regex. my $myrep1 = "@\\abc"; # escape backslash once for the regex. my $mystring = "some string containing \\abc \\abc a couple of times"; # escape backslash once for the definition. $mystring = ~s/$mytest1/$myrep1/g; print "$mystring\n"; will print:
some string containing @\abc @\abc a couple of times Which is what you say you want. If not, it would help if you told us what these strings are and what they're for. Cheers, Larry
|