in reply to How do I test if a file has write permission?

Another, but probably less efficient way, is to open the file in append mode. If the open fails the file COULD be read-only:

open(FILE, ">>some_file.txt") || print "File is read only";

The advantage of this way, I suppose, is that if you really want to write things to the end of the file then it's now open :)

Replies are listed 'Best First'.
Re: Answer: How do I test if a file has write permission?
by exussum0 (Vicar) on Dec 20, 2003 at 20:58 UTC
    Open fails when it can't write, period. So if a directory where a file is expected or you have an NFS timeout, this will fail for non-permission reasons.

    (Why would your current directory be missing? If someone else rm's it of course :)


    Play that funky music white boy..