Front page | perl.beginners |
Postings from March 2002
Testing for filehandles
Thread Next
From:
eric-perl
Date:
March 27, 2002 13:23
Subject:
Testing for filehandles
Message ID:
Pine.LNX.4.33.0203271210180.20427-100000@lucy
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.,
use Getopts::Std;
getopts("n");
open(OPT_LOG,">/tmp/foo.txt") if ($opt_n);
while (<>) {
print OPT_LOG $_ if OPT_LOG;
}
close(OPT_LOG) if OPT_LOG;
--
Eric P.
Los Gatos, CA
Thread Next
-
Testing for filehandles
by eric-perl