in reply to Why is it uninitialized?

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?