daddygoofball has asked for the wisdom of the Perl Monks concerning the following question:

In linux, How do you call a perl script from a perl script and print the output to the screen and to a log file?

Answer:

#!/usr/bin/perl -w `clear`; print "\n\n\n\n What is the Passing Variable? "; my $ans = <STDIN>; chomp $ans; system("perl some_perl_script.pl -s $ans -r | tee -a ./log/$ans.log 2> +&1");

I couldn't find this answer when I was looking. I figured it out and thought this might help someone else

Replies are listed 'Best First'.
Re: Perl script Print to Screen and log
by wind (Priest) on Mar 10, 2011 at 18:32 UTC
    Or use a pure perl solution using backticks to capture the results.
    #!/usr/bin/perl -w use strict; `clear`; print "\n\n\n\n What is the Passing Variable? "; my $ans = <STDIN>; chomp $ans; my $results = `perl some_perl_script.pl -s $ans -r`; my $file = './log/$ans.log'; open my $fh, '>>', $file or die "$file: $!'; print $fh $results; close $fh; print $results;