fmogavero has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone else run into the following problem on NT, and if so is there a solution?

$diss = "bleen"; mkdir $diss,777;
does not create a directory.(in the current directory of course)

However

mkdir "bleen\\",777;
works like a charm.

Even mkdir ($diss,777); does not work.

I'm clueless. Can anyone explain this?

Replies are listed 'Best First'.
Re: mkdir on NT
by Albannach (Monsignor) on Mar 28, 2001 at 00:14 UTC
    Well all three of your versions work fine on this NT box. If you want a clue, perhaps it's time to add an error check and find out just what is going on in your case? mkdir $diss,777 or die "Can't mkdir: $!";

    Update: Yes that should be 0777 (an octal number) rather than 777. It happens that 0777 is also the default mask so it could actually be left out in this case.

    --
    I'd like to be able to assign to an luser

      Thank you for the suggestion. I had not included the  $! at the end of my  die message.

      The two error codes that I receive when it fails are "file exists", which tells me that it will not try to go any further because it found the directory.

      The other message is just the opposite. "No such file or directory at file.pl line 2."

      if !($dir){ mkdir $dir,777 or die "Cant mkdir: $!"; }
      Does not explain the second message which occurs only when I use a scalar.
        Methinks you mean   mkdir $dir, 0777 or ... rather than   mkdir $dir, 777 or... The leading '0' is significant (less so on Win32, more so on *nix).

Re: mkdir on NT
by diskcrash (Hermit) on Mar 28, 2001 at 00:29 UTC

    I use the following syntax on NT 4.0 SP6a with no problems. $outdir is a preamble, fixed path and $fname is a new subdir.

    mkdir($outdir.$fname,0777);

    I agree, check for the error, as above.

    -Diskcrash

      Today it behaves differently. Now it is only allowing me to create one directory with no subdirectories under it. All of the following work:
      $diss = "\\bleen\\"; mkdir $diss,0777 or die "can't make dir: $!"; $diss = "\\bleen\\"; mkdir "$diss",0777 or die "can't make dir: $!"; $diss = "\\bleen\\"; mkdir ($diss,0777) or die "can't make dir: $!"; $diss = "\\bleen\\"; mkdir ("$diss",0777) or die "can't make dir: $!";
      If I extend my directory structure, it fails. For example
      $diss = "\\bleen\\duh\\";
      fails.
      I know that there is more than one way to do it. I usually go the least terse route. I could test for the directory and create it if it doesn't exist. Then I could change into the directory and test for the sub directory and create it if it doesn't exist, but that seems like the long way home to me.
Re: mkdir on NT
by fmogavero (Monk) on Mar 28, 2001 at 21:36 UTC
    The solution to the problem is use File::Path;
    When the mkdir is replaced with mkpath, everything functions as expected.

    Thanks to everyone who helped!