in reply to Filehandle open?
The fcntl function allows you to read the filehandle's modes. If *FOO is open and you want to see if it is writeable:
On many systems fcntl will return '0 but true' if the handle is open read only, so a writeable handle will return numeric zero or else have the O_RDWR bit set.# named constants for portability use Fcntl qw( F_GETFL O_WRONLY O_RDONLY O_RDWR); if ( (O_WRONLY | O_RDWR) & fcntl( FOO, F_GETFL, 0) ) { # g'wan and write }
If the handle is not open fcntl returns undef.
Update: Aristotle, yes, but it would be good to check $! the see just what the error was. EBADF says the handle isn't open.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Filehandle open?
by Aristotle (Chancellor) on Sep 24, 2002 at 14:37 UTC |