Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

How do I test if I file exists without attaching a filehandle to it?

by Anonymous Monk
on May 22, 2000 at 06:49 UTC ( #14132=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: (files)

I have an application where I need to check if I file exists without actually modifying it in any way except for reading it's file name. What is the most common way of doing this?

Originally posted as a Categorized Question.

  • Comment on How do I test if I file exists without attaching a filehandle to it?

Replies are listed 'Best First'.
Re: How do I test if I file exists without attaching a filehandle to it?
by ZZamboni (Curate) on May 22, 2000 at 18:41 UTC
    Note that most file test operators imply existence when they return a true value. So -r actually means "exists and is readable", and so on. So if you are interested not only on existence, but on some other specific condition of the file, you can simply use the appropriate operator and skip -e altogether.
Re: How do I test if I file exists without attaching a filehandle to it?
by athomason (Curate) on May 22, 2000 at 07:00 UTC
Re: How do I test if I file exists without attaching a filehandle to it?
by galande (Initiate) on Nov 24, 2000 at 13:13 UTC
    Hi,
    Use operators like -e, -r, -T for testing file permissions.
    (-e <FILE/FILEHANDLE> returns true if file exists. -r <FILE/FILEHANDLE> returns true if file is readable. -T <FILE/FILEHANDLE> returns true if file is a text file.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2021-04-23 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?