Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: How do I tell if a handle is open for writing?

by DrWhy (Chaplain)
on Nov 07, 2005 at 17:16 UTC ( #506448=note: print w/replies, xml ) Need Help??


in reply to Re: How do I tell if a handle is open for writing?
in thread How do I tell if a handle is open for writing?

Correct me if I'm wrong here, but doesn't -w myfilehandle tell you whether the file that myfilehandle is pointing to has its writable bits set? That's not what I want to know. I want to know if the filehandle is open for writing. You could open a writable file for reading. Then you couldn't write to it with that handle even though passing that handle to -w would still return true. Or have I been smoking the curtains again?

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

  • Comment on Re^2: How do I tell if a handle is open for writing?

Replies are listed 'Best First'.
Re^3: How do I tell if a handle is open for writing?
by Zaxo (Archbishop) on Nov 07, 2005 at 19:06 UTC
    Or have I been smoking the curtains again?

    No, the curtains are safe. I've added to my reply a sub that Does What You Want.

    After Compline,
    Zaxo

      Ah. That looks much more to the point :) I like this fcntl()-based solution better than sgifford's solution (print nothing) because it more directly answers the question at hand. Which is not to say that sgifford's solution is bad; it has the advantage that it will catch some writability problems not related to how the handle was opened, plus it looks less complex to the human reader of your code.

      Unfortunately, I'm doing this on Win32 :( Win32 doesn't implement the fcntl() function, so I'll go with the 'print nothing' solution for now.

      --DrWhy

      "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://506448]
help
Chatterbox?
LanX 1 ..2 ..3 ..4 .. is erix missing ;-)
LanX is Discipulus reciting "Springtime for Hitler" ?
[choroba]: erix could tell you how to do it in Postgres
[LanX]: NOOOOOOOOOOOOOOO not again
[chacham]: wow, mysql really is as bad as i thougt
[choroba]: completion?
[LanX]: That's what he usually does when MySQL is mentioned ;-)
[chacham]: the same thing could be achieved with a trigger
[LanX]: choroba yes
chacham shudders at the thought of using a trigger...so evil

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2017-03-30 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (360 votes). Check out past polls.