Dynamically changing STDOUT and STDERR redirects

In Perl, I use standard printing commands:

print "text"; # STDOUT print STDOUT "text"; print STDERR "text"; 

How can I dynamically change the redirect of STDOUT and STDERR to different files?

Let's say I have a simple loop with $i going from $min to $max , and I want to dynamically change the redirects to the files "out_$n" and "err_$n" files where $n = int($i/1000)

I don't want to change existing existing print commands, so I'm looking for a solution that will simply add this redirection function without changing the existing code.

+4
source share
1 answer

Just open STDOUT

 open(STDOUT, '>', $qfn) 
+8
source

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


All Articles