http://qs321.pair.com?node_id=187087

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

Hello guys, I know this is an easy one but since I am new , I would have problems like this : I need to check weather a file exists or not under a certain directory ,, the file
$targetFile = "theFile"
and I know the directory as well,
/bin/do/foo
so I need to know if it exists under foo, knowing that I am not under foo when searching for that file or I could be as well, I tried the -e and local but don't seem to work ,, thanks for hints on this one .

Replies are listed 'Best First'.
Re: checking for a file
by dada (Chaplain) on Aug 02, 2002 at 14:02 UTC
    if(-e "/bin/do/foo/$targetFile") { print "is there!\n"; } else { print "someone stoled it...\n"; }
    cheers,
    Aldo
    __END__ $_=q,just perl,,s, , another ,,s,$, hacker,,print;
      I'd rather go with
      if(-f "/bin/do/foo/$targetFile") { print "is there!\n"; } else { print "someone stoled it...\n"; }
      to check if it's actually a file (that exists), as the -e may also return true on a directory.
        Thanks all , I was able to figure it out with the -f ,, thank you again
Re: checking for a file
by dreadpiratepeter (Priest) on Aug 02, 2002 at 14:01 UTC
    What's wrong with:
    my $exists = -e "/bin/do/foo/$theFile";



    -pete
    "Pain heals. Chicks dig scars. Glory lasts forever."