while ( my ($punctuation, $count) = each(%wordHash) ) { $wordArray[my $i] = "$count\t$punctuation"; $i++; print ("$count\t$charnames{$punctuation}\n"); }
Each time round that loop, you create a new variable called $i which is uninitialised (and therefore contains "undef"). You then use that variable as an array index. As it contains "undef", Perl converts it to a zero, but warns you that it has done so. You then increment the variable and let it go out of scope. A new (undefined) $i is created the next time round the loop.
What you probably want is this:
while ( my ($punctuation, $count) = each(%wordHash) ) { push @wordArray, "$count\t$punctuation" print ("$count\t$charnames{$punctuation}\n"); }
Had you looked at the contents of @wordArray, you would have seen the problem.
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
In reply to Re: unitialized values - HELP!
by davorg
in thread unitialized values - HELP!
by Yoda_Oz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |