Print to standard file and file at the same time

I have a Perl script with several print statements. Is there a way by which I can direct all these print statements to a file, as well as to stdout at the same time without duplicating print statements?

+6
source share
1 answer

You can use File :: Tee .

use File::Tee qw(tee); tee STDOUT, '>>', 'some_file.out'; print "w00p w00p"; 

If File::Tee not available, it is easy to model using the pipeline:

 open my $tee, "|-", "tee some_file.out"; print $tee "w00p w00p"; close $tee; 
+9
source

Source: https://habr.com/ru/post/945432/


All Articles