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

This node was taken out by the NodeReaper on Apr 03, 2012 at 10:27 UTC
  • Comment on Reaped: Re^2: print the output on the screen and to a file

Replies are listed 'Best First'.
Re^3: print the output on the screen and to a file
by tobyink (Canon) on Mar 30, 2012 at 13:48 UTC

    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'
      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"); ----------