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

RE: Testing for filehandles

Thread Previous | Thread Next
From:
Bob Showalter
Date:
March 28, 2002 05:55
Subject:
RE: Testing for filehandles
Message ID:
2E4528861499D41199D200A0C9B15BC031B925@FRISTX
> -----Original Message-----
> From: eric-perl@pretorious.net [mailto:eric-perl@pretorious.net]
> 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 

   defined(fileno(F))

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About