in reply to STDERR Restore after redirect
Why save and restore when local() will do that for you.
#!/usr/bin/perl # http://perlmonks.org/?node_id=1213644 use strict; use warnings; warn "before on STDERR\n"; test(); warn "after on STDERR\n"; sub test { my $log = ''; local *STDERR; open STDERR, '>', \$log or die; warn "test message should be in log\n"; close STDERR or die; print "log contents: $log"; }
Outputs:
before on STDERR log contents: test message should be in log after on STDERR
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: STDERR Restore after redirect
by tultalk (Monk) on Apr 27, 2018 at 03:54 UTC | |
by Anonymous Monk on Apr 27, 2018 at 13:02 UTC |