in reply to Re: Re: Sending STDOUT to Multiple Sockets
in thread Sending STDOUT to Multiple Sockets

no good. I inserted
tie *STDOUT, 'IO::Scalar', \$a; ...stuff... print $client $a; untie *STDOUT;
in all of the appropriate locations and always got a warning about using an unitialized value. I think part of the problem is that the original C code (this is a wrapped C API I am using) actually uses a pointer to STDOUT instead of STDOUT proper. I don't know if this would be a significant issue but I'm starting to think it is.

Replies are listed 'Best First'.
Re (tilly) 4: Sending STDOUT to Multiple Sockets
by tilly (Archbishop) on Aug 18, 2001 at 23:03 UTC
    If this is a wrapped C API the odds are good that it is just getting a file descripter and issuing a print at a level that is too low for the tie mechanism to intercept.

    If that is the case, then your best solution is to have two processes, one of which is reading from the other, the other of which writes to all of the sockets. You can do this in various ways with fork, etc. (The Cookbook has this exact problem as an example.)

    UPDATE
    Alternate solution. Create a temporary file (for instance with File::Temp) and then let the code write to that, seek back to the beginning of the file, read it and write to the sockets, seek back and truncate. Not as immediate, but it solves the problem without creating a new process.