Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Shell scripts and perl

by Sara (Acolyte)
on Aug 05, 2002 at 14:53 UTC ( #187684=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://187684]
Approved by grep
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2020-07-09 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?