in reply to Handling returns from mkdir.

mkdir does not give any standard output. In case of failure of mkdir you see the error output which is not returned by backtick (``) operators. You may have to redirect error output to standard output to capture it.

my $op = `mkdir winlog 2>&1`;

On my system the error message in case of pre-existence of directory is "cannot create directory `winlog': File exists" which will fail your regular expression. I think using the return codes is a better idea than using the error output. You can get the return code in $?

For all codes returned by the mkdir check the detailed manual of the command

Update: As pointed by corion and marto below mkdir of perl is the correct option. My answer is more concerned with the way of getting output rather than the approach.

--
Regards
- Samar

Replies are listed 'Best First'.
Re^2: Handling returns from mkdir.
by marto (Cardinal) on Dec 24, 2010 at 09:24 UTC

    Perl has a mkdir function built in, there's no need to rely on an external command.

      You are right. In the above answer I was just concerned with the way of output. I should have thought on the approach itself.

      Thanks marto.

      --
      Regards
      - Samar

      Hi marto,

      Thats actually what I was looking for..managed to use the built in command instead.

      I have been trying to find other errors reported by $!(File exists being the only one that kept coming up with the code), without any luck.

      I know this sounds pretty silly but, can you please tell me how i can find them(maybe a list of some sort)....im still a newbie.

      Thanks for all the help so far!!

        On the system documented by this man page, mkdir can return the following:
        • EACCES
        • EEXIST
        • EFAULT
        • ELOOP
        • ENAMETOOLONG
        • ENOENT
        • ENOMEM
        • ENOSPC
        • ENOTDIR
        • EPERM
        • EROFS

        Those constants are provided by Errno and via %!. Don't rely on the stringification except for display purposes, because that depends on the system's locale.