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

Excellent suggestions, monks.

I don't really see the problem in the same way, however. If the problem is here:
my $output; # this value is unintialized open my $old_stdout, '>&=', \*STDOUT; close STDOUT; # Use of uninitialized value in open at the following line open STDOUT, '>', \$output;
It's not an issue of 'spitting warnings at the second opening of a memory file'. $output really is uninitialized, and STDOUT, when its called, is already initialized. So it actually spits a warning the first time.

What I'm trying to say is that the warning is thrown more or less as expected. It's been pointed out that setting $output='' will fix the problem. Also... turning off 'use warnings' would probably silence it, but I wouldn't know because I never turn off warnings.

I hope this helps.
Bro. Doug :wq

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 19:33 UTC

    So it actually spits a warning the first time.

    Where does that warning go? It's not on my screen when I run it. As I see it, $output is uninitialized both times, but the warning is not printed the first time.

    I'm confused also because what I pass to open is a reference to $output which is always a real value regardless of whether $output is initialized or not.

      I see where I went wrong.

      To give a more concise answer to this question, I got the code to run and saw the results just as you reported. So I started experimenting.

      I noticed there are a lot of operations on references happening here, which makes me leery when you're mucking with global symbols (STDOUT, for instance). So I took $output and gave it persistence in scope:
      our $output ; # changed 'my' to 'our'
      The problem went away.

      By the way, I agree with the monks who suggested using select().

      Peace, monks.
      Bro. Doug :wq