in reply to Restoring STDOUT and STDERR after having redirected them to files

Have you reviewed the examples in the documentation for open on saving and restoring STDOUT and STDERR? I suspect that your glob assignments are overwriting each other, rather than saving the old values.
  • Comment on Re: Restoring STDOUT and STDERR after having redirected them to files

Replies are listed 'Best First'.
Re: Re: Restoring STDOUT and STDERR after having redirected them to files
by isotope (Deacon) on Jan 12, 2001 at 22:53 UTC
      Ah... But, reading a little further down in the documentation for open...
      If you specify '<&=N', where N is a number, then Perl will do an equivalent of C's fdopen() of that file descriptor; this is more parsimonious of file descriptors. For example: open(FILEHANDLE, "<&=$fd")
      So, using fileno() on your globs, you can dup your filehandles like in the open example, except with the numbers instead of the names! An updated snippet from your code:
      # restore STDOUT my $fd = fileno($this->{'_stdout'}); open(STDOUT, ">&=$fd"); print STDOUT "STDOUT restored\n";