in reply to How do i determine which mode the file has open ? (write or append mode)

While this is actually an interesting question, and I appreciate very much salva's answer, I would say that it's not something that would pop up frequently. Indeed in many years I've never felt the need to find out the open mode of a filehandle: generally you're the person who opens it in the first place and thus you do know how to deal with it. Since you claim to be a newbie, I'd be curious as to know what you need this for. After all this may be an XY Problem...

  • Comment on Re: How do i determine which mode the file has open ? (write or append mode)

Replies are listed 'Best First'.
Re^2: How do i determine which mode the file has open ? (write or append mode)
by gellyfish (Monsignor) on Apr 21, 2006 at 10:14 UTC

    Actually I can think of quite a few use cases for this: in an abstract sense you aren't always the person who opened the file in the first place such as when you are passing a filehandle to a subroutine or method, particularly if the subroutine or method is written by a third party. I'm actually going to have some code that does this in the next release of Term::ReadKey to catch some 'bugs' that seem to crop up on windows.

    /J\

      Indeed. Though, even if I pass the handle to a sub or method, end even if they're written by someone else, in most cases I do know what they will do with it, i.e. whether they will read from it or write into it. I can imagine situations in which I won't know and I will desire to find out the open mode of the handle, but I would regard them as atypical, especially for a newbie: this is why I asked...