Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

mkdir unless dir already exists.

by c (Hermit)
on Aug 21, 2001 at 23:01 UTC ( [id://106690]=perlquestion: print w/replies, xml ) Need Help??

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

I have the following:

mkdir("$tftpdir/$archive", 755) unless ( -d $tftpdir/$archive );

which seems like it can be shortened. Would something like this work:

mkdir("$tftpdir/$archive", 755) unless exists;

Would it this be equal to/better than the -d test?

humbly -c

Replies are listed 'Best First'.
Re: mkdir unless dir already exists.
by Beatnik (Parson) on Aug 21, 2001 at 23:08 UTC
    exists is for hash keys... you can use
    mkdir("$tftpdir/$archive", 755) || warn $!;
    or the bit you used.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: mkdir unless dir already exists.
by mugwumpjism (Hermit) on Aug 21, 2001 at 23:20 UTC

    38 characters:

    $_="$tftpdir/$archive";-d||mkdir$_,755

    Or if you can assume that the user has a decent umask value set, we're down to 34:

    $_="$tftpdir/$archive";-d||mkdir$_

    Oh, sorry, I must be in the wrong place, could anyone direct me to the green?

      mkdir"$tftpdir/$archive";
      Less ;)

      T I M T O W T D I

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found