in reply to How to test for open file handles?

As a preventive measure, I'd suggest restructuring code to make use of lexical filehandles as shown. Always open a lexical $FH in a BLOCK:
{ open(my $FH, "<", $filename) or die("Cannot open: $filename\n $!"); while (<$FH>) { ... }; # unnecessary - $FH gets closed once it leaves lexical scope #close($FH); }

Replies are listed 'Best First'.
Re^2: How to test for open file handles?
by mikegrb (Initiate) on Feb 04, 2009 at 14:21 UTC
    I'd argue that the close is necessary. Sure the file handle will be closed implicitly when it goes out of scope but then you can't check the result. It's just as import to check the return value of close() as it is to check the return value of open, if not more so... particularly when a file is being written to. That, said lexically scoped file-handles are always a good idea.