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

Richard Anderson richard at richard-anderson.org
Fri Mar 1 12:59:55 CST 2002


Thanks for the correction.  Since File::Path is part of the standard Perl
distribution and is five years old, I would have expected accurate
documentation.  Perhaps I should have looked elsewhere than "perldoc
File::Path"?  Is this (I hope) an aberration or are module users expected to
scan the source code before using a module?

Cheers,
Richard
richard at richard-anderson.org
www.richard-anderson.org
www.raycosoft.com
----- Original Message -----
From: "Colin Meyer" <cmeyer at helvella.org>
To: "Richard Anderson" <richard at richard-anderson.org>
Cc: "Yitzchak Scott-Thoennes" <sthoenna at efn.org>; <spug-list at pm.org>
Sent: Friday, March 01, 2002 10:15 AM
Subject: Re: SPUG: Re: Using mkpath (was: HTTP::Cookies question)


> Hi Richard,
>
> On Fri, Mar 01, 2002 at 07:03:00AM -0800, Richard Anderson wrote:
> > No need to use eval, which introduces unneeded complexity and slows
> > execution speed. File::Path::mkpath returns the number of directories
>
> Eval with a string form can slow execution speed, but eval with the
> block form is the appropriate way to capture fatal errors, and causes
> no significant speed slowdown.  You can test with Benchmark; I have.
>
> > successfully created, so the right way to call it is:
> >
> > use File::Path qw(mkpath);
> > unless (mkpath($nameOfNewDir)) {
> >     die "Can't create directory $nameOfNewDir: $!";
> > }
>
> Despite the lacking documentation, File::Path's mkpath *does* throw
> a fatal error if it encounters problems creating a directory.  Here's
> the offending line from that module:
>             croak "mkdir $path: $e" unless -d $path;
>
> Your code's die statement will never be reached if there is a problem.
> If you asked mkpath to make no directories, then your code could reach
> the die statement.
>
> Try:
> #!/usr/local/bin/perl
> use File::Path;
>
> my $result = mkpath('/usr/bogus');
> print $result?'yay':'nay', "\n";
> __END__
>
> The print statement never gets run, because the fatal error aborts the
> program before hand.
>
> Have fun,
> -C.
>


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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