Lets say I want my program to print to STDOUT unless the user
specifies that the output goes to a file.  Here is my code:



my $oldhandle=undef;
if($user_input ne 'STDOUT') {           #user specify output to a file
    open (OUT,">$temp.txt") or die "Can't open the file\n";
    $oldhandle = select OUT;
}

print "blah blah blah\n";

select ($oldhandle) if(defined($oldhandle));  #restore STDOUT as default

At this point I want to close my FileHandle (OUT) if it was open.  My 
question is HOW do I check to see whether a filehandle(OUT) has been opened 
so I can explicitly close it with

close(OUT);


thanks
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

Reply via email to