in reply to Uninitialized Value

@data starts out with 1 element: "" (the empty string), from when you initialize it. $data[1], $data[2], $data[3], and $data[4] are all uninitialized.

As you go through the last foreach loop, you (might) assign $_ to specified elements of @data. On line 49, you print all the elements of @data - some of which are obviously uninitialized.

You can initalize them with something like the following:

my @data = ('','','','','');
To have it start it's life with 5 empty strings.

Also, consider moving the open/close statemens outside of the foreach loop.

open STDOUT, ">>", "$output0" or die "$output0: $!\n"; foreach (@list) { ... print STDOUT, @data; } close STDOUT;
Since you're appending to the output file, you might as well just open it once and be done with it.

Update: Fastolfe pointed out that the initialization should have been with the empty string instead of undef...thanks.

Replies are listed 'Best First'.
Re: Re: Uninitialized Value
by Fastolfe (Vicar) on Dec 15, 2001 at 00:23 UTC
    You don't want to "initialize" to undef. All scalars start out as 'undef', so this is precisely what perl is looking for when emitting this warning. If you want to initialize a variable, initialize it to something that makes sense for your application. In this case, @data is being printed out as a string, so an empty string might be appropriate.
    $ perl -we 'print undef' Use of uninitialized value in print at -e line 1.