I am trying to determine if a given scalar holds a filehandle. It could have been passed to me from a bareword filehandle (i.e. \*FH), a lexical filehandle, an IO::Handle, an IO::File, etc. So far, the only thing that seems to be consistent amongst the various flavors is that they all have a reftype of "GLOB".
I am trying to determine if a given scalar holds a filehandle. It could
Share
Use the openhandle function from Scalar::Util:
The current implementation is similar to Greg Bacon’s answer, but it has some additional tests.