wrote:
> I want to replace the "\" backslash character in a string e.g: my
> $test = "C:\myroot\folder"; with forward slash "/"
Do you really have a file that is named
c:myroot[formfeed]older
where [formfeed] indicates the form feed character?
Or did you mean
$test = 'C:\myroot\folder';
If so, then please be advised that using backward slashes in filenames is
not a bad idea (you just saw one reason why) and you should use forward
slashes instead, even on Windows which will happily work with forward
slashes, too.
> This is what my snippet, which seems to be not doing anything....
> $test =~ s|\|/|g;
Really? For me it is generating two error messages:
Unrecognized escape \m passed through at [...]
Substitution replacement not terminated at [...]
You didn't get those?
Your substitute command will replace globally a vertical bar followed by a
forward slash against .... well, you didn't write the substitution string.
Did you mean
$test =~ s|\\|/|g;
instead?
Anyway, for this kind of transliteration the tr() command is more suitable:
$test =~ tr|\\|/|;
jue