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

The issue seems real. Consider:

use strict; use warnings; wibble (); wibble (); sub wibble { my $unicode16Str; open my $UTF, '>:encoding(UTF-16LE)', \$unicode16Str; print $UTF "Wibble"; close $UTF; }

Generates:

Use of uninitialized value in open at noname1.pl line 10.

for the second call. However changing my $unicode16Str; to my $unicode16Str = '';

runs clean. Making $unicode16Str global to the sub is also fine. A closure issue perhaps?


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Use of uninitialized value in open second time but not first.
by blazar (Canon) on Jun 05, 2007 at 09:26 UTC
    open my $UTF, '>:encoding(UTF-16LE)', \$unicode16Str;

    That may be a completely different issue.

      I don't think so. The warning is only issued for the second open. The code otherwise works as expected. Initialising the output buffer ($unicode16Str) resolves the issue. Making the output buffer global also resolves the issue.


      DWIM is Perl's answer to Gödel