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

The question says it all
  • Comment on How do I test whether a file has write permission?

Replies are listed 'Best First'.
Re: How do I test whether a file has write permission?
by chromatic (Archbishop) on Apr 20, 2000 at 21:57 UTC
    The -w test will do:
    if (-w FILEHANDLE) { print "It's writeable by my effective uid or gid!\n"; }
    For more information, see -X (or perldoc -f -X).
Re: How do I test whether a file has write permission?
by btrott (Parson) on Apr 20, 2000 at 22:04 UTC
    Another option, if you're interested in determing the actual permissions of the file in a symbolic format (ie. what you'd get back from ls -l):
    my $file = "foo"; use Stat::lsMode; my $mode = file_mode($file);
    $mode now contains something like "-rw-r--r--".
      Thanks guys! This is what I was trying to do, and it works! -DataTracer
      if (!(-w FILE)) { print "Content-type: text/plain\n\n"; print "Error: This file does not have write permission!\n"; exit; }