open my $oldSTDOUT, ">&STDOUT";
open OLDERR, ">&",\*STDERR;
open(STDOUT, ">&", $oldSTDOUT) or warn("Can't open STDOUT");
+
open(STDERR, ">&OLDERR") or warn("Can't open STDERR");
Neither published a warn | [reply] [d/l] |
Is this not a test for a file handle?
I would say no. Neither of these statements indicate failure in any way:
open my $oldSTDOUT, ">&STDOUT";
open OLDERR, ">&",\*STDERR;
AFAIU, both of these statements indicate failure of file handle restoration if it occurs, but give no indication that the handle was valid prior to restoration:
open(STDOUT, ">&", $oldSTDOUT) or warn("Can't open STDOUT");
open(STDERR, ">&OLDERR") or warn("Can't open STDERR");
I still don't really understand the basic problem. Maybe you can find something in the following:
c:\@Work\Perl\monks>perl -wMstrict -le
"open oldSTDOUT, '>&', \*STDOUT or warn qq{duping STDOUT: $!};
print oldSTDOUT 'hi there everybody';
print STDOUT '... and welcome';
print '... to the show.';
if (defined *oldSTDOUT) { warn 'A: *oldSTDOUT is defined'; }
;;
close STDOUT or warn qq{closing STDOUT: $!};
print STDOUT 'how now';
print '... brown cow.';
if (defined *STDOUT) { warn 'B: *STDOUT is defined'; }
;;
open STDOUT, '>&', \*oldSTDOUT or warn qq{re-opening STDOUT: $!};
print oldSTDOUT 'aloha';
print STDOUT '... sweet dreams';
print '... and goodbye.';
if (defined *oldSTDOUT) { warn 'C: *oldSTDOUT is defined'; }
if (defined *STDOUT) { warn 'D: *STDOUT is defined'; }
"
hi there everybody
... and welcome
... to the show.
A: *oldSTDOUT is defined at -e line 1.
print() on closed filehandle STDOUT at -e line 1.
print() on closed filehandle STDOUT at -e line 1.
B: *STDOUT is defined at -e line 1.
aloha
... sweet dreams
... and goodbye.
C: *oldSTDOUT is defined at -e line 1.
D: *STDOUT is defined at -e line 1.
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] [select] |