I am new to perl.
In a string How do I replace a backward slash with a forward slash?
when I call the following perl api $FindBin::Bin; I get the path as follows
$myPath = c:/perl/test
I would like to covert this to
c:\perl\test
I did try the following and get errors
#$myPath=~ tr/\//\/c;
alan_123
0
Newbie Poster
Recommended Answers
Jump to Post#!/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";
Jump to PostSorry, 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 …
Jump to Post…#!/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";
Jump to PostBlank 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 …
All 14 Replies
d5e5
109
Master Poster
alan_123
0
Newbie Poster
d5e5
109
Master Poster
rocky martin
0
Newbie Poster
d5e5
109
Master Poster
alan_123
0
Newbie Poster
maaria
0
Newbie Poster
dozierc
0
Newbie Poster
d5e5
109
Master Poster
mitesh.24jain
0
Light Poster
mitesh.24jain
0
Light Poster
swapnilkesharka
0
Newbie Poster
Arrtti
0
Newbie Poster
Taywin
312
Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.