in reply to test if a scalar contains a filename or a filehandle?


I just noticed that the Scalar::Util module by gbarr recently added a function called openhandle().

From the pod:

openhandle FH Returns FH if FH may be used as a filehandle and is open, or FH is a tied handle. Otherwise undef is returned. $fh = openhandle(*STDIN); # \*STDIN $fh = openhandle(\*STDIN); # \*STDIN $fh = openhandle(*NOTOPEN); # undef $fh = openhandle("scalar"); # undef
It uses several methods, including fileno(), to try to determine if the scalar is a valif FH.

--
John.