From: Perl 5 Porters Date: Tue, 23 Jul 1996 21:05:27 +0000 (+0000) Subject: Close file only once during object destruction. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f75e77c7ab132742fcbf797d7186eb143939446e;p=p5sagit%2Fp5-mst-13.2.git Close file only once during object destruction. --- diff --git a/ext/FileHandle/FileHandle.pm b/ext/FileHandle/FileHandle.pm index 2770b91..a6d1dda 100644 --- a/ext/FileHandle/FileHandle.pm +++ b/ext/FileHandle/FileHandle.pm @@ -252,7 +252,19 @@ sub new_from_fd { sub DESTROY { my ($fh) = @_; - close($fh); + + # During global object destruction, this function may be called + # on FILEHANDLEs as well as on the GLOBs that contains them. + # Thus the following trickery. If only the CORE file operators + # could deal with FILEHANDLEs, it wouldn't be necessary... + + if ($fh =~ /=FILEHANDLE\(/) { + local *TMP = $fh; + close(TMP) if fileno(TMP); + } + else { + close($fh) if fileno($fh); + } } ################################################