How to check if a file is exist or not?

S

Samwyse

John said:
if ( -e 'filename' ) {
print "'filename' exists.\n";
}


John, John, John. *sigh* You didn't answer his question. You should
have said, "Yes", and then given the perldoc references.
 
J

Juha Laiho

John W. Krahn said:
if ( -e 'filename' ) {
print "'filename' exists.\n";
}

However, be careful if later on performing any action based on the
knowledge that at some point in the history the file did exist.

Most often, one is interested, whether a piece of data can be read
from a file - and in this context it'd be better to attempt to
open the file and read the data. Just encapsulate the functionality
performing this to allow an upper level to process and report the
error appropriately.
 
R

Rich

if ( -e 'filename' ) {
print "'filename' exists.\n";
}


perldoc -f -e
perldoc -f stat


John

Thanks for the perldoc tip. I've used it for different modules I've had to work
with, but haven't tried to for basic usage. Usually rely on my O'Reilly manual
as a cheat sheet for information like that, but now I have a quicker solution.

Rich
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top