http://qs321.pair.com?node_id=11141789

fireblood has asked for the wisdom of the Perl Monks concerning the following question:

Dear wise ones,

I have a "bad file descriptor" problem in one of my Perl programs that I’ve been unable to resolve. I've looked at the other topics on perlmonks and other fora with bad file descriptor in their descriptions but didn't see enough similarities to my problem to resolve it.

My program has the following initial instructions in it:

unless (open ($fh_debug, ">>", $self -> {debug_file_name})) { print STDERR "\nCould not open \$fh_debug: $!\n"; die; }

The open works just fine, and throughout the program I am able to write many messages to the file referenced by $fh_debug.

At the end of the program, I have the following instructions:

line_no 480 print $fh_debug "jj\n"; 481 482 print $fh_debug "\$fh_debug is defined\n" if (defined ($fh_debu +g)); 483 484 if (close ($fh_debug)) 485 486 { 487 <do some stuff>; 488 } 489 490 else 491 492 { 493 print STDERR "\nCould not close \$fh_debug: $!\n"; 494 die; 495 }

When I invoke the module in which this code resides from Strawberry Perl v5.32.1, it works exactly as expected. The last lines in the debug file are

jj $fh_debug is defined

and the program finishes nicely and cleanly. But when I invoke the module from Linux Perl v5.34.0, I again get those same two lines at the end of the debug file, and then get the following message:

Could not close $fh_debug: Bad file descriptor Died at /u1/stat/global/bin/perllib/master_log.pm line 494. Can't use an undefined value as a symbol reference at /u1/stat/global/ +bin/perllib/master_log.pm line 480.

What could be causing this? Why would it work perfectly under Strawberry Perl but seem to write its final messages correctly and then paradoxically issue those error messages under (Red Hat 7) Linux Perl?

Thank you.

P.S. How can I prevent the lines between my < code > and < /code > tags from wrapping prematurely?