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

Ok I know this must have a stupid answer:

How do I check for he existance of a file ( binary or text ) without opening the file and seeing if it fails open or not?

Thats the only way I can think of doing it and I am stumped , I am running BSD and could open a pipe read in the directory with ls and then split the list and check but there I guess is a better way ( and no so fragile )

Angel

Replies are listed 'Best First'.
Re: Existance of a file
by Zaxo (Archbishop) on Oct 23, 2002 at 00:04 UTC

    You are looking for the file test operators -e "filename" or -f "filename". The former tests existance of anything with that name, the latter tests for a regular file.

    After Compline,
    Zaxo

Re: Existance of a file
by grantm (Parson) on Oct 23, 2002 at 00:07 UTC
    if(-e $filename) { print "$filename exists"; }

    For more details see: perldoc -f -x