A
anonyusenet
I need to store my match and replace strings in variables.
This fails when my match string uses back references to groupings.
Here for example I try to replace "foo" with "foobar" using a back
reference:
#!/usr/bin/perl
$content = "this is my foo";
$match = "(foo)";
$replace = "\1bar";
#$replace = "\\1bar"; # this doesn't work either
#$replace = "$1bar"; # neither does this
$content =~ s/$match/$replace/;
print "$content\n"
Any ideas how to get this to work? I need the match and replace strings
in variables because I am reading them from file.
Thanks!
This fails when my match string uses back references to groupings.
Here for example I try to replace "foo" with "foobar" using a back
reference:
#!/usr/bin/perl
$content = "this is my foo";
$match = "(foo)";
$replace = "\1bar";
#$replace = "\\1bar"; # this doesn't work either
#$replace = "$1bar"; # neither does this
$content =~ s/$match/$replace/;
print "$content\n"
Any ideas how to get this to work? I need the match and replace strings
in variables because I am reading them from file.
Thanks!