Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How do I test if a file has write permission?

by fx (Pilgrim)
on Dec 19, 2003 at 23:35 UTC ( [id://315951]=note: print w/replies, xml ) Need Help??


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..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://315951]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found