in reply to How do I test whether or not a file is writable?

if(-f $name ) { if(!(-w $name)) { print "File '$name' doesn't have write permission\n"; } }

-f switch is used to check whether $name is file or not.
-w switch is used to test whether file has write permission or not.

Replies are listed 'Best First'.
Re: Answer: How do I test whether or not a file is writable?
by JavaFan (Canon) on Mar 18, 2010 at 14:34 UTC
    There's no point testing for both -f and -w. If the file doesn't exists (or if its existence cannot be determined), -w will return false. And if -w returns true, the file exists.
      Yes, but -w would also return true if the file is actually a writeable directory