All the variables are declared using my at the beginning of the sub

FWIW, you're supposed to aim for smallest scope necessary, you'll develop this skill with practice :)(Tutorials: Variables and Scoping)

Compare Silenced, Loudmouth, and Smooth (always strive for Smooth)

#!/usr/bin/perl -- use strict; use warnings; use diagnostics; use Data::Dumper(); Main( @ARGV ); exit( 0 ); sub Main { warn Dumper( Silenced('hello') ), ' '; warn '------' x 6; warn Dumper( Loudmouth('loud') ), ' '; warn '------' x 6; warn Dumper( Smooth('cop') ), ' '; } ## end sub Main sub Dumper { Data::Dumper->new( \@_ )->Indent(0)->Useqq(1)->Dump; } sub Silenced { no warnings 'uninitialized'; my @string_array = @_; my @string; my $basecount; my $pos; my $pos_score; my @temp_array; my %base_stat; foreach (@string_array) { @string = split( //, $_ ); $basecount = 0; foreach $pos (@string) { $basecount++; $pos_score = ord($pos) - 33; @temp_array = $base_stat{$basecount}; # line 124 push( @temp_array, $pos_score ); $base_stat{$basecount} = "@temp_array"; } ## end foreach $pos (@string) } ## end foreach (@string_array) return \%base_stat; } ## end sub Silenced sub Loudmouth { my @string_array = @_; my @string; my $basecount; my $pos; my $pos_score; my @temp_array; my %base_stat; foreach (@string_array) { @string = split( //, $_ ); $basecount = 0; foreach $pos (@string) { $basecount++; $pos_score = ord($pos) - 33; warn Dumper( \%base_stat ), ' '; @temp_array = $base_stat{$basecount}; # line 124 push( @temp_array, $pos_score ); $base_stat{$basecount} = "@temp_array"; } ## end foreach $pos (@string) } ## end foreach (@string_array) return \%base_stat; } ## end sub Loudmouth sub Smooth { my %base_stat; for my $str (@_) { my $basecount = 0; for my $pos ( split( //, $str ) ) { $basecount++; my $pos_score = ord($pos) - 33; #~ $base_stat{$basecount} = $base_stat{$basecount} ." ". $pos_score; # + loud $base_stat{$basecount} .= " ". $pos_score; # smooth } ## end for my $pos ( split( //...)) } ## end for my $str (@_) return \%base_stat; } ## end sub Smooth __END__ $ perl pm.897159.pl $VAR1 = {4 => " 75",1 => " 71",3 => " 75",2 => " 68",5 => " 78"}; at +pm.897159.pl line 13. ------------------------------------ at pm.897159.pl line 14. $VAR1 = {}; at pm.897159.pl line 62. Use of uninitialized value $temp_array[0] in join or string at pm.8971 +59.pl line 66 (#1) (W uninitialized) An undefined value was used as if it were alread +y defined. It was interpreted as a "" or a 0, but maybe it was a mi +stake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl will try to tell y +ou the name of the variable (if any) that was undefined. In some cases it + cannot do this, so it also tells you what operation you used the undefine +d value in. Note, however, that perl optimizes your program and the opera +tion displayed in the warning may not necessarily appear literally in y +our program. For example, "that $foo" is usually optimized into "that + " . $foo, and the warning will refer to the concatenation (.) operat +or, even though there is no . in your program. $VAR1 = {1 => " 75"}; at pm.897159.pl line 62. $VAR1 = {1 => " 75",2 => " 78"}; at pm.897159.pl line 62. $VAR1 = {1 => " 75",3 => " 84",2 => " 78"}; at pm.897159.pl line 62. $VAR1 = {4 => " 67",1 => " 75",3 => " 84",2 => " 78"}; at pm.897159.p +l line 15. ------------------------------------ at pm.897159.pl line 16. $VAR1 = {1 => " 66",3 => " 79",2 => " 78"}; at pm.897159.pl line 17.
Questions?

In reply to Re: Why is it uninitialized? by Anonymous Monk
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.