in reply to Reaped: Re^2: print the output on the screen and to a file
in thread print the output on the screen and to a file

If there are many such print statements, then define a function to handle it:

sub my_tee { my $handle = shift; print $handle @_; print @_; } open my $fh, '>>', 'output.txt' or die "$!"; my_tee $fh => ("Greetings!\n"); my_tee $fh => ("Hello", " ", "World");
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^4: print the output on the screen and to a file
by rkshyam (Acolyte) on Mar 31, 2012 at 06:18 UTC
    Thanks to everyone for your replies. I have used this code suggested by "tobyink" and it worked for me. -------- If there are many such print statements, then define a function to han +dle it: sub my_tee { my $handle = shift; print $handle @_; print @_; } open my $fh, '>>', 'output.txt' or die "$!"; my_tee $fh => ("Greetings!\n"); my_tee $fh => ("Hello", " ", "World"); ----------