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

Hello monks , I know you can do the follwing using shell scripting :
if [ ! -d $BA/bs/eerel/esGH060 ]; then mkdir $BA/bs/eerel/esGH060
how would I do the same thing in perl?

Replies are listed 'Best First'.
Re: Shell scripts and perl
by frankus (Priest) on Aug 05, 2002 at 15:22 UTC
    Consider using -e instead, if a file of the same name exists the mkdir command will fail.

    --

    Brother Frankus.

    ¤

Re: Shell scripts and perl
by dreadpiratepeter (Priest) on Aug 05, 2002 at 14:59 UTC
    my $dir = "$BA/bs/eerel/esGH060"; mkdir($d) unless -d $d;


    -pete
    "Pain heals. Chicks dig scars. Glory lasts forever."
Re: Shell scripts and perl
by Abigail-II (Bishop) on Aug 05, 2002 at 15:19 UTC
    mkdir "$BA/bs/eerel/esGH060" or $! =~ /^File exists/ or die $!;
    Abigail
Re: Shell scripts and perl
by hotshot (Prior) on Aug 05, 2002 at 15:01 UTC
    using perl's mkdir:
    if (! -d "$BA/bs/eerel/esGH060") { mkdir("$BA/bs/eerel/esGH060"); }
    almost the same as shell scripting

    Thanks.

    Hotshot
Re: Shell scripts and perl
by runrig (Abbot) on Aug 05, 2002 at 17:57 UTC
    As already mentioned, mkdir is what you want, but if one of those intermediate directories doesn't exist, and you'd like to create the whole path in one go, you can use File::Path.