Hi PerlMongers,

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


In reply to Porting Perl 5.6 to Perl 5.8 issue with self-tie by fwashbur

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.