SPUG: Re: Using mkpath (was: HTTP::Cookies question)
Colin Meyer
cmeyer at helvella.org
Fri Mar 1 12:15:56 CST 2002
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