If the path is entered from the command line, you need not tamper with the backslashes. (See the code below.)

Also, I notice that cmd.exe on Win2K treats:

c:\mydir
and
c:\\mydir

as equivalent. For example, the following works fine:

md c:\\mydir\yourdir pushd c:\mydir\\yourdir popd

Here is some code that takes a path from the user and creates the specified directory:

print "Enter string: "; $dirname = <STDIN>; # # Must chop the string that the user entered, # since mkdir won't accept a directory name # that contains a newline character. # chop $dirname; # # This line is optional (at least on # Win2K), since cmd.exe considers # c:\mydir and c:\\mydir to be # equivalent. # # So double the slashes or not, # as you please. # $dirname =~ s{\\}{\\\\}g; print "Creating . . . $dirname\n"; mkdir($dirname, 0777) || die "Couldn't create $dirname. Error: $!\n";

Carl-Joseph


In reply to Re: Converting all occurrences of \ to \\ oddity by Carl-Joseph
in thread Converting all occurrences of \ to \\ oddity by dmtelf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.