Use local *STDERR:
my $out; print STDERR "before\n"; { local *STDERR; open STDERR, ">", \$out or die; print STDERR "during\n"; } print "after\n"; print "out: $out\n";
Output:
before after out: during
In reply to Re: Redirecting STDOUT, lexically scoped
by FunkyMonk
in thread Redirecting STDOUT, lexically scoped
by moritz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |