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:  <%-{-{-{-<


In reply to Re^7: STDERR Restore after redirect by AnomalousMonk
in thread STDERR Restore after redirect by tultalk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.