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

I have ran into a small mkdir problem that is a little confusing. First, let me give you a copy of my code:
#!/usr/bin/perl -w use strict; my $dir = "doug"; mkdir($dir, 0777) or die "Couldn't make directory $dir: $!; aborting";

The problem is that the best permissions I can get is:
drwxr-xr-x 2 root root 4096 May 20 08:16 doug

If I set the permissions to 0711 then I get what I expect. However I cannot get above a 0755. The parent directory is currently 0777. I am thinking that this may be related to the Perl Install on the OS. It is a 5.6.1 install on Redhat 7.2. Has anyone else had this problem? Or, am I looking in the wrong place?

Replies are listed 'Best First'.
Re: mkdir problem
by zby (Vicar) on May 20, 2003 at 12:54 UTC
    Are you aware of the umask command? If not just type man umask at the command prompt.
      Yes, I was making the assumption I was getting a umask of 022 (which I find to be true). I just felt that it was odd that running the script as root (with the options of setting permissions by perl's mkdir function) was governed by a different set of rules than on the shell.

      It was just odd to me why mkdir can't complete the task while chmod can without setting the umask.

      I did not know until now that umask was available in Perl. Thanks a million.

      Doug