K
kj
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
*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