I
Ilya Zakharevich
Re the subject: 10 years ago I would check
defined fileno $fh
But nowadays, filehandle does not necessarily has an OS file
descriptor associated to it...
I could also check *$fh{IO} - but it would be defined if, e.g., $fh is
\*FOO, and a bareword FOO was *mentioned* in the code at place where
filehandle is expected (the code may not be ever executed, just
mentioning is enough). Moreover, I expect that *$fh{IO} survives
after close()ure of $fh.
I could do
defined eval { seek $fh, 0, 1 }
but the answer is ALWAYS defined (although sometimes ''), and, to add
insult to injury, would send a warning in my wake...
So: what should one do to check that $fh is open()?
Thanks,
Ilya
defined fileno $fh
But nowadays, filehandle does not necessarily has an OS file
descriptor associated to it...
I could also check *$fh{IO} - but it would be defined if, e.g., $fh is
\*FOO, and a bareword FOO was *mentioned* in the code at place where
filehandle is expected (the code may not be ever executed, just
mentioning is enough). Moreover, I expect that *$fh{IO} survives
after close()ure of $fh.
I could do
defined eval { seek $fh, 0, 1 }
but the answer is ALWAYS defined (although sometimes ''), and, to add
insult to injury, would send a warning in my wake...
So: what should one do to check that $fh is open()?
Thanks,
Ilya