What does if( -f ) in Perl do?

后端 未结 5 2119
谎友^
谎友^ 2021-02-05 03:10

I came across this line of code:

if( -f  ) { ... }

-f appears to test whether the filename exists or not, but I am

5条回答
  •  醉梦人生
    2021-02-05 03:50

    In Unix, directories can contain the following types of files:

    • Plain (what you would consider a file)
    • Directory
    • Named pipe
    • Named socket
    • ...

    -f tests if the provided name references a file that's a plain file. It will return undef (error ENOENT) if the file doesn't exist, or some other false values if the file exists but it's not plain file (e.g. if it's a directory).

    -X operators

提交回复
热议问题