Without going into details; I have the need to pass a string containing double backslashes \\ from the DOS command line and convert these to single backslashes in the code.
The problem is if I do this from within perl code directly it is no problem but when I attempt to pass a string from the command line, it seems to lose something in the translation and when I try to do the replace it does not work. So the question is HOW to pass the string from the command line so it works. Here is the sample code that works without passing from the command line:
perl source code = test_string_replace21.pl:
- #!/usr/bin/perl -w
-
use strict;
-
# replacing double back slash...
-
my $string1 = "-----\\---------";
-
$string1 =~ s/"\\"/"\"/g;
-
print "The resulting value is : $string1 \n";
This of course works:
- C:\>
-
C:\>test_string_replace21.pl
-
The resulting value is : -----\---------
As you can see, the double back slash is changed to a single one as expected.
But now use the following code which should do the same thing as above but takes the string as argument from the command line:
perl source code = test_string_replace2.pl:
- #!/usr/bin/perl -w
-
use strict;
-
my $string1 = $ARGV[0];
-
$string1 =~ s/"\\"/"\"/g;
-
print "The resulting value is : $string1 \n";
-
I run it from DOS command line:
- C:\>test_string_replace2.pl "-----\\-----"
-
The resulting value is : -----\\-----
As you can see, the double back slash is still there!!!!! Why????? And how do I get around it?
Thanks to anyone who can help.