>At 3:28 AM 11/27/95, Tom Christiansen wrote:
>>I think you really strongly want to pass a filehandle reference, not
>>a string reference.
>>
>> \*STDOUT
>>
>>is a globref (file handle ref). \STDOUT is either a scalar reference
>>if STDOUT is but a string, or else it's a code refernce is there's a sub
>>STDOUT.
>
>Argh, that was the first thing I tried (having skimmed some of that p5p
>discussion), but I kept getting
> Unable to redirect STDERR: Invalid argument
>during the following:
>
> open(SAVEERR, ">&STDERR");
> open(STDERR, ">&${$fh}") or
> ( print SAVEERR "Unable to redirect STDERR: $! \n" and exit(1) );
>
>I tried a bunch of variations on the second open(), including
> ">&$fh"
> ">&${$fh}"
> ">&${pack}::${$fh}"
> ">&main::$fh"
> ">&main::${$fh}"
>Always the same error. I tried your code this morning and it got the same
>error. If I change the call back to carpout(\FH) from carpout(\*FH), it
>works again. So that's what I was using.
>
>Is it possible to duplicate a filehandle glob? Where in the man pages are
>filehandle globs covered? (I couldn't find anything on Sunday while I was
>doing this.)
This is another part of the annoyance of filehandles being a rickety
construct in perl. If you get one that's a proper filehandle instead
of this oh-so-horrible strings, then you can't always do the right things
with them. In particular, >& redirection for dup's is broken. Here's
the work-around:
$fd = fileno($fh); # should work for all of them
open(NEWFD, ">&$fd"); # dup()
open(NEWFD, ">&=$fd"); # fdopen()
--tom
>>I think you really strongly want to pass a filehandle reference, not
>>a string reference.
>>
>> \*STDOUT
>>
>>is a globref (file handle ref). \STDOUT is either a scalar reference
>>if STDOUT is but a string, or else it's a code refernce is there's a sub
>>STDOUT.
>
>Argh, that was the first thing I tried (having skimmed some of that p5p
>discussion), but I kept getting
> Unable to redirect STDERR: Invalid argument
>during the following:
>
> open(SAVEERR, ">&STDERR");
> open(STDERR, ">&${$fh}") or
> ( print SAVEERR "Unable to redirect STDERR: $! \n" and exit(1) );
>
>I tried a bunch of variations on the second open(), including
> ">&$fh"
> ">&${$fh}"
> ">&${pack}::${$fh}"
> ">&main::$fh"
> ">&main::${$fh}"
>Always the same error. I tried your code this morning and it got the same
>error. If I change the call back to carpout(\FH) from carpout(\*FH), it
>works again. So that's what I was using.
>
>Is it possible to duplicate a filehandle glob? Where in the man pages are
>filehandle globs covered? (I couldn't find anything on Sunday while I was
>doing this.)
This is another part of the annoyance of filehandles being a rickety
construct in perl. If you get one that's a proper filehandle instead
of this oh-so-horrible strings, then you can't always do the right things
with them. In particular, >& redirection for dup's is broken. Here's
the work-around:
$fd = fileno($fh); # should work for all of them
open(NEWFD, ">&$fd"); # dup()
open(NEWFD, ">&=$fd"); # fdopen()
--tom