in reply to STDOUT to multiple files

Thanks for your reply. Unix tee command helped me this time.
open(STDOUT,"| tee $log_file"); print "Testing";

This piece of code writes testing to the log file as well as to the terminal.
-perl_lover-

Replies are listed 'Best First'.
Re^2: STDOUT to multiple files
by Skeeve (Parson) on Sep 13, 2006 at 09:54 UTC

    But you need not call it inside the script itself. You can also append the tee to the script invocation.

    OTOH: When it's your script, you can also change all your print commands to "logger" commands and do the proper output there. That way you don't depend on any other module and need not call an external program.

    #each print "this is my ",$test; # would become logger("this is my ", $test);

    You will also need to have a logger function and a LOGFILE. Something like this

    open LOGFILE, '>>', $log_file; sub logger { print LOGFILE @_ if defined $log_file; print @_ }

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e