flycast has asked for the wisdom of the Perl Monks concerning the following question:

I an learning perl by necessity I have a If statement that has the form: if ( condition1 || -f file path) Condition1 is a simple condition. The -f after the || looks like a file command that is checking for the presence of a file. What does -f do in this situation?

Replies are listed 'Best First'.
Re: What does -f mean
by bart (Canon) on Dec 17, 2006 at 16:44 UTC
    See -X and perlop. -f is one of the several unary file test operators (compare to the "-" in -$x).

    To explicitely answer you question: -f returns true if file path exists and is a plain file (as opposed to a directory, for example).

Re: What does -f mean
by davido (Cardinal) on Dec 17, 2006 at 16:45 UTC

    -f tests its right-hand argument to see if it's a file. You can read about it in the Perl documentation in the Functions section under -X. In this case -X is just symbolic of all the different "dash whatever" tests. Here's a link: -X.

    Basically it returns true if the argument is a name of a real file in your current working directory, and false if not.


    Dave

Re: What does -f mean
by Cabrion (Friar) on Dec 18, 2006 at 03:00 UTC
    type "perldoc -f -X" on the command line. Note that -f here means "show me the docs for built-in function" and -X is the function.