Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Creating new folders

by plobsing (Friar)
on Feb 03, 2008 at 03:20 UTC ( #665790=note: print w/replies, xml ) Need Help??

in reply to Creating new folders

A couple things:
  • If you aren't woried about error results of mkdir (maybe you should be, but you aren't checking right now), you don't need to check if the directory exists. If it exists, the function returns an error (which you don't check, so to you it won't make a difference).
  • the File::Path core module contains a nice function called mkpath which recursively checks parent dirs to make sure they exist before making the directory of interest
  • Long path values should be kept in a constant or a variable somewhere
  • if(! ...) is better written as unless( ... ), this is more of a personal style thing, but at least use if (not ... ) as both are more readable
Here's how I'd do it:
use File::Path 'mkpath'; use constant DIR => 'e:/web/public_html/eagle_f91...'; unless (-d DIR) { mkpath(DIR) or die "Could not mkpath: $!\n" }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://665790]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2021-10-22 14:31 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (85 votes). Check out past polls.