in reply to How to verify a file handle?
fileno() works as you'd expect on both bare filehandles (eg, STDERR) and on references (eg, those returns from CGI::param and CGI::upload).if (defined(fileno($fh))) { print "Filehandle!\n"; } else { print "Not a filehandle\n"; }
Trap for the unwary: Zero is a perfectly legal fileno, which is usually bound to STDIN. Hence you should always check to make sure that fileno returns a defined value, not just a true one. Otherwise you can get caught out if you're testing STDIN for filehandle-ness, or if your STDIN has been closed and something else has taken fileno 0 as its own.
Cheers,
Paul
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2 (no to fileno): How to verify a file handle?
by tilly (Archbishop) on Oct 02, 2001 at 21:00 UTC |