Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Skipping files in a directory

by ccn (Vicar)
on Dec 11, 2008 at 10:51 UTC ( [id://729659]=note: print w/replies, xml ) Need Help??


in reply to Skipping files in a directory

perldoc -X
foreach my $dir (@DIRS) { warn "Directory $dir not found!\n" and next unless -d $dir; # # work with existing directory here # }

Replies are listed 'Best First'.
Re^2: Skipping files in a directory
by svenXY (Deacon) on Dec 11, 2008 at 10:55 UTC
    ++ccn as it is obviously much better to check for the existence of a directory before trying to open it and warn on failure
      as it is obviously much better to check for the existence of a directory before trying to open it and warn on failure

      That might be OK here, but in the general case it is not, because of race conditions. If you check for the existence of a directory, and then open it, it might be deleted by another process between these two operations.

      Thus you have to do the error checking anyway, and don't gain anything by another call to stat (which most file test ops do).

      That's why the general philosophy with file access and IO is "try and see if it worked", not "first test if it might work, and then try".


      Thanks a lot svenXY and ccn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found