May 2, 2009, 7:32 AM
Post #8 of 9
Re: [vikas.deep] how to check if the file already exists?
[In reply to]
but my code simply tells "how to check if the file already exists
No, that's not what your code does.
The open function can fail and execute the die statement even if the file exists, for example if you don't have read permission or the file is opened and locked by another process. The -e file test is what is used to do the exists check, not the open function and not the defined function. However, if the user neglected to test the return code of the open call, then an if block such as yours could be used to check the status/value of the filehandle, but if the filehandle is not defined would that be because the file doesn't exist or because of some other reason?