You can use fileno to find out if a filehandle is open, but it's a much better idea to make sure the open() succeeded in the first place, as suggested above.
Note: the 'fileno' documentation referred to on perlmonks.org is incomplete. The documentation included with perl 5.6.1 includes this: Returns the file descriptor for a filehandle, or undefined if the filehandle is not open.
Example:
sub chk_hndl { if (fileno $_[0]) { print "OPEN\n" } else { print "NOT OPEN\n" } } chk_hndl(*FOO); chk_hndl(*STDOUT); # prints: NOT OPEN OPEN
conv
In reply to Re: Bad File Descriptors Gone Wild
by converter
in thread Bad File Descriptors Gone Wild
by chaoticset
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |