Perl replace slash in variable

Posted by cc96ai on Stack Overflow See other posts from Stack Overflow or by cc96ai
Published on 2010-06-03T19:44:23Z Indexed on 2010/06/03 19:54 UTC
Read the original article Hit count: 232

Filed under:

How can I replace the slash inside the variable?

$string = 'a\cc\ee';
$re = 'a\\cc';
$rep = "Work";

#doesnt work in variable
$string =~ s/$re/$rep/og;
print $string."\n";

#work with String
$string =~ s/a\\cc/$rep/og;
print $string."\n";

output:

a\cc\ee
Work\ee

© Stack Overflow or respective owner

Related posts about perl