SPUG: Re: Using mkpath (was: HTTP::Cookies question)

Richard Anderson richard at richard-anderson.org
Fri Mar 1 09:03:00 CST 2002


No need to use eval, which introduces unneeded complexity and slows
execution speed. File::Path::mkpath returns the number of directories
successfully created, so the right way to call it is:

use File::Path qw(mkpath);
unless (mkpath($nameOfNewDir)) {
    die "Can't create directory $nameOfNewDir: $!";
}

Cheers,
Richard
richard at richard-anderson.org
www.richard-anderson.org
www.raycosoft.com
----- Original Message -----
From: "Yitzchak Scott-Thoennes" <sthoenna at efn.org>
To: <spug-list at pm.org>
Cc: <richard at richard-anderson.org>
Sent: Thursday, February 28, 2002 9:22 PM
Subject: Re: SPUG: Re: HTTP::Cookies question


> In article <00a801c1c0a2$303a5a10$2088ddd1 at aciwin>,
> "Richard Anderson" <richard at richard-anderson.org> wrote:
> >On an unrelated note, it is more portable and less error prone to use
> >use File::Path;
> >mkpath($newdir)
> >
> >than
> >system "mkdir -p $newdir"
> >since on some OSes mkdir does not have the -p option.
>
> To be equivalent, you need to make that:
> eval { mkpath($newdir) }
> since mkpath croaks on errors.
>
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>       Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>   Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
>  For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
>      Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
>
>
>


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list