fwashbur has asked for the wisdom of the Perl Monks concerning the following question:
I have a problem for which I can't seem to find a solution. We have a huge 5.6 code base and are looking at porting to 5.8. Most everything is going well except for one area. I have searched all the Perl books, CPAN, Google, etc to find a solution but have been unsuccessful.
We took advantage of what sounds like a hole in 5.6 and did a self-tie of STDOUT to itself and a log file. STDERR was tied to the same log file and itself. This allowed us to capture all print/printf output in text logs from sessions with both STDOUT and STDERR as well as seeing this output on the screen. 5.6 was somehow able to detect that it needed to call print with the real handle one time and not recurse. It may have been a bad thing to do, but it mades sense to us and worked like a charm.
On 5.8, the upgrade notes say self tie is not allowed and in fact it does cause a recursive call to print.
I have tried saving a global value for STDOUT, doing a local STDOUT and passing the global value to the Tie class and print to that. This works, but I can only get either STDOUT or STDERR to work in this situation, not both.
I have tried using the suggestion from the Perl Cookbook 7-18:
open(STDOUT, "| tee $outfile); print "whatever\n"; close(STDOUT);
Which fails miserably. There are several problems with this. Upon close, the tee process does not die. Attempts to kill the tee process after the close result in tee not being able to run again during that process (it complains about arguments???) If I add 'or die' to the close call it fails as there seems to be an issue with closing STDOUT. Also upon close, STDOUT is now undef and cannot be used unless opened again. If I open another log file after closing the first, all print output now goes to the 1st AND 2nd file (2 tee processes now running).
I have tried overriding print and that seems like it is not allowed. Perhaps there is a way to do this that I have not found, I tried the function re-definition example from O'Reilly but it needs to work for print.
If anyone has ideas on how to:
1. cause output from print and printf
2. for both STDOUT and STDERR
3. to go to successive log files within the same perl 5.8 session I would be extremely grateful.
Thanks - Rick
Rick Washburn
Qualcomm Inc. 928-478-4663
|
|---|