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

RE: Testing for filehandles

Thread Previous | Thread Next
From:
Bob Showalter
Date:
March 27, 2002 14:40
Subject:
RE: Testing for filehandles
Message ID:
2E4528861499D41199D200A0C9B15BC031B91E@FRISTX
> -----Original Message-----
> From: eric-perl@pretorious.net [mailto:eric-perl@pretorious.net]
> Sent: Wednesday, March 27, 2002 3:18 PM
> To: Beginners Perl Mailing List
> Subject: Testing for filehandles
> 
> 
> Hello, All:
> 
> I've looked around for an answer to this (The Camel Book, The 
> Ram Book, 
> perldoc, google.com, etc.) but can't find a thing: Is it 
> possible to test 
> for the existence of a filehandle?
> 
> I've got a small script that <optionally> opens a filehandle. If that 
> filehandle exists, I'd like to print to it. Otherwise, don't. e.g.,
> ...

You can pass a filehandle glob to IO::Handle::opened():

   use strict;
   use IO::Handle;

   open(F, "<foo") or die;
   ...
   print "F is open\n" if IO::Handle::opened(*F);

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