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


In reply to Re: Why is it uninitialized? by davido
in thread Why is it uninitialized? by yehudithasin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.