in reply to Converting all occurrences of \ to \\ oddity

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

Replies are listed 'Best First'.
RE: Re: Converting all occurrences of \ to \\ oddity
by cwest (Friar) on Sep 13, 2000 at 22:42 UTC
    Just a note:

    You may consider using File::Path so the user can create a diretory structre.

    That would be cool :-)

    --
    Casey
       I am a superhero.