in reply to Print to the screen and a log at the same time?

sub _print { my ($msg) = @_; print $msg, "\n"; print LOG $msg, "\n"; } _print("hello"); _print("world");
--

when small people start casting long shadows, it is time to go to bed

Replies are listed 'Best First'.
Re^2: Print to the screen and a log at the same time?
by ikegami (Patriarch) on May 09, 2006 at 15:59 UTC

    Why not

    sub _print { print $msg, @_; print LOG $msg, @_; } _print("hello"); _print("world");

    That way, you can print lists, and $, and $\ will be obeyed. OTOH, the simplest solution is probably the following:

    use IO::Tee (); my $fh_out = IO::Tee->new(\*STDOUT, \*LOG); select($fh_out); print("hello"); print("world");

    But there are problems with using select.