Can one use local to temporarily close STDERR?






I would like to know whether it is possible to use localization to
*temporarily* close a global handle, e.g. STDERR. The following
doesn't work (all three messages appear on the screen):

warn "before closing\n";
{
local *STDERR;
# close STDERR;
warn "should be closed\n";
}
warn "still here\n";

If I explicitly close STDERR right after the local statement, then
only the first message gets printed.

Of course, I can achieve the desired effect (namely, selectively
silencing the second message) if I explicitly save and later restore
STDERR:

use Fatal qw( open close );
warn "before closing\n";
{
open my $save, '>&', *STDERR;
close STDERR;
warn "should be closed\n";
open STDERR, '>&', $save;
}
warn "still here\n";

....but I'm curious if there's a way to achieve the same effect without
doing this.

Thanks!

kj

--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
.



Relevant Pages

  • Re: email module, redirecting to stdout
    ... > The problem is that whenever I set the debuglevel to 1, ... > to stderr. ... I would like them to go to stdout. ... to get the desired effect. ...
    (comp.lang.python)
  • Re: email module, redirecting to stdout
    ... >> to stderr. ... I would like them to go to stdout. ... > to get the desired effect. ... "from sys import stderr" should at least ...
    (comp.lang.python)
  • Re: zsh: STDERR to a variable?
    ... one wanted to capture both stderr *and* stdout. ... I meant capturing both stderr and stdout ... In my address everything before the first period is backwards; ...
    (comp.unix.shell)
  • Re: print sybase system stored procedure output to filehandle
    ... However there are tricks you can use in Perl to capture STDERR and/or ... STDOUT from subprocesses and black-box Perl subroutines. ... open STDERR, '>&', $log; ... helper process as soon as you open the filehandle and then wrote to the ...
    (comp.lang.perl.misc)
  • Identify if a scalar is int, double or text
    ... The first is obviously an int, the second is text, the third a double ... print STDERR "Beginning of program\n"; ...
    (comp.lang.perl.misc)