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

The problem with the approach shown in perlfunc:open is that it requires the name of the filehandle, and I have only the glob.

--isotope
http://www.skylab.org/~isotope/
  • Comment on Re: Re: Restoring STDOUT and STDERR after having redirected them to files

Replies are listed 'Best First'.
Re: Re: Re: Restoring STDOUT and STDERR after having redirected them to files
by chipmunk (Parson) on Jan 12, 2001 at 23:07 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";