develooper Front page | perl.beginners | Postings from March 2002

RE: Testing for filehandles

Thread Previous | Thread Next
Bob Showalter
March 28, 2002 05:55
RE: Testing for filehandles
Message ID:
> -----Original Message-----
> From: []
> Sent: Wednesday, March 27, 2002 6:16 PM
> To: Beginners Perl Mailing List
> Subject: RE: Testing for filehandles
> On Wed, 27 Mar 2002, Bob Showalter wrote:
> > You can pass a filehandle glob to IO::Handle::opened():
> Thanks, Bob! After reading the IO::Handle man page, I decided 
> to distill 
> this approach a bit further:
>   print F if fileno(F);

Of course, that's even simpler! Just to be nitpicky, the test maybe 
should be 


Since 0 is a valid file number (STDIN).

If you're just going to do the test on the print statement, it's
not accomplishing all that much, since the print() will silently
fail if the file isn't open. But a test like this would be useful
if you want to avoid doing a lengthy operation to generate the
data to be printed.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About