#!/usr/bin/perl -w
#ReplaceBackslashWithSlash.pl
use strict;
my $myPath = 'c:\perl\test'; # Example string containing backslashes
print "\nOriginal string is: $myPath\n\n";
# The following command substitutes backslashes with forward slashes
# You need to escape the backslash and slash with backslash
$myPath =~ s/\\/\//g;
print "Modified string is: $myPath\n";
d5e5
Practically a Posting Shark
831 posts since Sep 2009
Reputation Points: 162
Solved Threads: 163
Skill Endorsements: 1
Sorry, I read your example wrong. This should do it. Too bad the substitute command uses slashes to delimit the two strings. It confuses me, but it should work this time.
#!/usr/bin/perl -w
#ReplaceSlashWithBackslash.pl
use strict;
my $myPath = 'c:/perl/test'; # Example string containing backslashes
print "\nOriginal string is: $myPath\n\n";
# The following command replaces forward slashes with backslashes
# You need to escape the backslash and slash with backslashes
$myPath =~ s/\//\\/g; #There must be a better way, but I don't know it.
print "Modified string is: $myPath\n";
d5e5
Practically a Posting Shark
831 posts since Sep 2009
Reputation Points: 162
Solved Threads: 163
Skill Endorsements: 1
Blank lines won't make any difference to how the program runs. Since I'm new to Perl I probably don't have a good sense of style yet. But I was trying to separate my code into three sections: introductory lines that appear in all programs, followed by setting up and printing the test string, followed by modifying and printing the resulting string.
d5e5
Practically a Posting Shark
831 posts since Sep 2009
Reputation Points: 162
Solved Threads: 163
Skill Endorsements: 1
Question Answered as of 3 Years Ago by
d5e5
and
rocky martin Welcome to Daniweb. Please start a new thread to ask your question. When you ask your question in a new thread, it will help if you list the script that you tried. Then maybe someone can advise you why your script didn't give you the result you wanted.
d5e5
Practically a Posting Shark
831 posts since Sep 2009
Reputation Points: 162
Solved Threads: 163
Skill Endorsements: 1