in reply to replacing backward slash with forward slash

Some people could want to use something like this instead, same result, different notation
$test = 'C:\first\second'; print $test, "\n"; $test =~ tr,\\,\/,; #or $test =~ tr [\\] [\/]; #or $test =~ tr <\\> <\/>; #or even $test =~ tr .\\.\/.; print $test, "\n";
I personally find it easier to read

Replies are listed 'Best First'.
Re^2: replacing backward slash with forward slash
by Gulliver (Monk) on Aug 19, 2011 at 14:44 UTC

    Actually you don't need the backslash escape for the slash if you use a different character for the delimiter.

    use strict; use warnings; my $test = 'C:\first\second'; print $test, "\n"; $test =~ tr,\\,/,; #$test =~ tr [\\] [/]; #$test =~ tr <\\> </>; #$test =~ tr .\\./.; print $test, "\n";
Re^2: replacing backward slash with forward slash
by DStaal (Chaplain) on Aug 19, 2011 at 16:45 UTC

    'tr' is also slightly more efficent than 's' since it doesn't have to try to evaluate as a regrex. (Of course, it's less powerful as well.)