in reply to Why is it uninitialized?

What does %base_stat contain before entering the first iteration of the loop? If %base_stat contains nothing, your first iteration of the loop will be performing operations on @temp_array when it too contains nothing. Perl is warning you that you're making a mistake. See the following snippet that should clarify for you.

use 5.012.02; use strict; use warnings; my %basestat; my @temparray; my $basecount = 1; @temparray = $basestat{$basecount}; say "\$temparray[0] is ", defined( $temparray[0] ) ? "defined." : "und +efined."; say "\@temparray has ", scalar(@temparray), " elements."; say "\$temparray[0] = $temparray[0]"; say "\@temparray = @temparray";

And the output:

Use of uninitialized value $temparray[0] in concatenation (.) or strin +g at test.pl line 14. Use of uninitialized value $temparray[0] in join or string at test.pl +line 15. $temparray[0] is undefined. @temparray has 1 elements. $temparray[0] = @temparray =

This snippet more or less constructs the state your code experiences on the first iteration of the loop. I'm surprised you're not getting a warning two lines later in the script too, where you wrap @temparray in quotes. On your subsequent loop iterations %basestat and @temparray contain values, and so you no longer are attempting to use the values of uninitialized variables, so your warnings go away.

I think if you dig a little deeper you'll find that there's a better way to do what you're trying to do.


Dave

Replies are listed 'Best First'.
Re^2: Why is it uninitialized?
by yehudithasin (Novice) on Apr 03, 2011 at 19:24 UTC
    Thank you I just did!
    push @{hash{$key},$value)
    works better:)