Perl's mkdir is an interface to the mkdir function, not the unix mkdir program which is a bit more sophisticated.

This is similar to how other calls work: you can type ln -s foo bar to command line if bar is a directory and it will act like ln -s foo bar/foo, but you can't do the same with the symlink call; rm will ask you if you want to remove a read-only file, while the unlink call won't; mv will move across file systems while rename won't; etc. Only this time the name of the utility is exactly the same as that of the system call.

(Note also that GNU coreutils has a few newer programs that correspond more to the system calls than the traditional utilities: link instead of ln, unlink instead of rm. A bit similar in spirit are stat and readlink instead of ls -l.)

Update: To clarify, the unix system call mkdir should behave this way, modifying the permission of the directory with umask, so the perl mkdir function behaves correctly. If you want to force specific permissions on the new directory, you have to call chmod after mkdir. Modifying the umask temporarily might not be enough if you want to control the extra bits (eg. setgid, sticky), as, depending on the system, these may get initialized independently of the umask and the permission value you pass to mkdir. For example, in linux, you typically need chmod to make a directory setgid.


In reply to Re: Why does unix mkdir and perl mkdir behave differently? by ambrus
in thread Why does unix mkdir and perl mkdir behave differently? by tphyahoo

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.