in reply to Redirection of output

For your second try, what you want is:

open(OUTPUT,">&STDOUT") or die "couldn't dup stdout: $!";
This is documented in perldoc -f open.

You can also accomplish what you want with the one-argument form of select. See perldoc -f select.

But I'm not sure why your first attempt won't work. This works fine for me:

#!/usr/bin/perl open(STDOUT,">/tmp/tempfile.html") or die "open: $!"; foreach my $i (1..10) { print $i,"\n"; }

Can you reduce your program to a smaller testcase and see if you can still reproduce the problem? Or can you reproduce the problem from the command-line and see what's going on?

Replies are listed 'Best First'.
Re: Re: Redirection of output
by michellem (Friar) on Sep 09, 2003 at 18:21 UTC
    Thanks, that works. I think my confusion about using the ">&STDOUT" syntax (that I did see in the camel book) had to do with duplication of STDOUT, which I didn't think I wanted. So it was just a matter of my ignorance of the issues.