To be more specific about the reference to local, this works:

use Symbol qw(gensym);
use Tie::FileHandle::Buffer ();
use Tie::FileHandle::MultiPlex();
my $fhBuffer = gensym;
my $buffer = tie *{$fhBuffer}, 'Tie::FileHandle::Buffer';
my $saveout = *STDOUT;
{
local *STDOUT;
tie *STDOUT, 'Tie::FileHandle::MultiPlex', $saveout, *{$fhBuffer};
# do all your logged STDOUT printing here
}

Since we saved the outermost (module-level) stdout, and the block stdout
is the tied one, everything seems hunky-dory... Now the question is, how
to do it without the local block fun...

-----Original Message-----
From: Nathan Herring [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 10, 2003 5:55 PM
To: [EMAIL PROTECTED]
Subject: "Tee"ing via "Tie"ing redux

Well, I had this great logging system set up for Jaguar (Perl 5.6.0)
where I would use Tie::FileHandle::Buffer and Tie::FileHandle::MultiPlex
to effect a "tee" setup where things printed to either (within Perl
anyway) would be also captured into a buffer for future inspection.

The basic setup was:

use Symbol qw(gensym);
use Tie::FileHandle::Buffer ();
use Tie::FileHandle::MultiPlex();
my $fhBuffer = gensym;
my $buffer = tie *{$fhBuffer}, 'Tie::FileHandle::Buffer';
my $saveout = *STDOUT;
tie *STDOUT, 'Tie::FileHandle::MultiPlex', $saveout, *{$fhBuffer};

Thereafter, if you printed to STDOUT, you'd get stuff on STDOUT and in
the $buffer object.

However, now I'm trying to get Panther running with the built-in 5.8.1
and it no longer works. As soon as you try to print, you end up with a
deep recursion error followed by a segment fault, probably caused by
5.8.1 taking the print to STDOUT and printing to the STDOUT tie (i.e.,
itself) and the buffer.

What changed in perl Ties such that this is now true, and is there a way
I can work around it?

I did find that if I put the MultiPlex tie in a "local *STDOUT;" block,
it doesn't have the problem. Unfortunately, this kind of design doesn't
work for the attach/detach style of logging that the module uses.

Any hints or suggestions would be appreciated...

Thanks,
nh


Reply via email to