use strict; use warnings; use File::Temp; use Symbol; { package MyWrapper; # VERY STRANGE - although this method is never called, if one # comments one or more lines below complains stop sub xxx { my $x=1; #comment this out:'temp', 'temp_keep' stop complaining my $y=2; my $z=3; } sub TIEHANDLE { my ($sClass, $self, $fh) = @_; $self = bless($self, $sClass); ${*$self}{io_window_fh} = $fh; return $self; } sub PRINT { my $self = shift; my $fh = ${*$self}{io_window_fh}; CORE::print $fh "@_"; } sub DESTROY { print STDERR "$_[0]: I'm dying...dead\n"; } } #--------------------------------------------------------------- # Select File Handle for test #--------------------------------------------------------------- # These complain: attempt to free unreferenced scalar # during global destruction my $fh; if (!$ARGV[0] || ($ARGV[0] eq 'temp')) { $fh = File::Temp::tempfile( UNLINK => 1); } elsif ($ARGV[0] eq 'temp_keep') { # This also complains $fh = File::Temp::tempfile( UNLINK => 0); } elsif ($ARGV[0] eq 'temp_unlink_name') { ($fh, my $name) = File::Temp::tempfile( UNLINK => 1); # BUT ALL THESE ARE OK } elsif ($ARGV[0] eq 'temp_keep_name') { ($fh, my $name) = File::Temp::tempfile( UNLINK => 0); } elsif ($ARGV[0] eq 'buf') { # no complaints with this file handle my $sBuf=''; open $fh, '+>', \$sBuf; } elsif ($ARGV[0] eq 'stdout') { # nor with this one $fh = \*STDOUT; } elsif ($ARGV[0] eq 'stderr') { # nor with this one $fh = \*STDERR; } else { # nor with this one open ($fh, '>', $ARGV[0]); } #--------------------------------------------------------------- # Demonstrate bug #--------------------------------------------------------------- my $fhWrapper = Symbol::gensym; tie(*$fhWrapper, 'MyWrapper', $fhWrapper, $fh); select $fhWrapper; print "Hello World\n"; print STDOUT "Done\n"; END { print STDERR "Global destruction beginning\n"; }