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