in reply to Use of uninitialized value in open second time but not first.

Would not it be easier to open() the scalar and select() the handle?

open my $FH, '>', \$output; my $old_FH = select($FH); print "Hello world\n"; select($old_FH);
Unless the code whose output you need to capture specificaly prints to STDOUT, this should work as well.

Replies are listed 'Best First'.
Re^2: Use of uninitialized value in open second time but not first.
by kyle (Abbot) on Mar 31, 2007 at 00:46 UTC

    Thanks for the suggestion!

    I actually don't know whether the code whose output I want to capture specifically prints to STDOUT (I didn't write it). I thought of the select solution too, but then I thought, "but what if it writes directly to STDOUT?" So I did this.

    The solution I had actually works but produces the warning. I mention the "real" problem just in case I'm doing something brainless.