Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change STDOUT and STDERR redirections

Tags:

perl

In Perl I use standard commands for printing:

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

How can I dynamically change redirection 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 redirections to files "out_$n" and "err_$n" files where $n = int($i/1000).

I don't want to change my existing print commands, so I am looking for solution that would just add this redirection functionality without changing of existing code.

like image 226
Ωmega Avatar asked Feb 15 '23 15:02

Ωmega


1 Answers

Just reopen STDOUT

open(STDOUT, '>', $qfn)
like image 94
ikegami Avatar answered Mar 03 '23 17:03

ikegami