in reply to Solving Deep recursion with a tied Filehandle

As mentioned in the CB, your code works in 5.6.1 and earlier, but not 5.8.??? However, I did get this to work in 5.8.4:
*FH = *STDOUT; { local *STDOUT; tie *STDOUT, 'FileHandle::A', *FH; print "testing"; }
Update: Just a note that the local above doesn't seem to do what I thought it would, that is, after the anonymous block, STDOUT is still tied (I thought it would get untied and return to it's original state). I think the correct thing would be to untie STDOUT (and maybe set it to the saved *FH) when you want the old STDOUT back. That still doesn't help cog, though :(

Replies are listed 'Best First'.
Re^2: Solving Deep recursion with a tied Filehandle
by ikegami (Patriarch) on Oct 14, 2005 at 18:39 UTC
    If you don't want it to localize STDOUT, the following works:
    { local *TEMP = *STDOUT; undef(*STDOUT); tie *STDOUT, 'FileHandle::A', *TEMP; } print "testing";
    and so does
    { my $temp = *STDOUT; undef(*STDOUT); tie *STDOUT, 'FileHandle::A', $temp; } print "testing";

    Tested on Perl 5.6.1 and 5.8.0

      None of those work with my 5.8.7
        How about
        { local *TEMP; open(TEMP, ">&STDOUT") or die("Unable to dup STDOUT: $!\n"); undef(*STDOUT); tie *STDOUT, 'FileHandle::A', *TEMP; } print "testing";
Re^2: Solving Deep recursion with a tied Filehandle
by cog (Parson) on Oct 14, 2005 at 16:58 UTC
    That doesn't segfault anymore, but neither does it print and it seems to run endlessly, while hanging my machine.

    I'm running 5.8.7.