Testing File Existence - best way?

S

still just me

I need to test if a file exists. Is there a better technique than
"attempt open and watch for an error"? The program will be a cgi
running in a windows or linux environment.

Thanks,
 
J

Jürgen Exner

still said:
I need to test if a file exists. Is there a better technique than
"attempt open and watch for an error"? The program will be a cgi
running in a windows or linux environment.

Why not use the "file exists" operator? See

perldoc -f -e

jue
 
J

Juha Laiho

Jürgen Exner said:
Why not use the "file exists" operator? See

perldoc -f -e

Commenting on an old thread here, but it depends on what the OP wants to
do with the file. Separate tests for file access permissions/file existence
may create possibilities for race conditions (if there's a possibility
that an existing file gets its permissions modified/gets removed
between the test and actual desired operation).

So, for most cases attempt to operate on the file in the desired way
(and handling arising error conditions) is the best test.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,269
Messages
2,571,100
Members
48,773
Latest member
Kaybee

Latest Threads

Top