
Yinyang107
New User
Dec 6, 2011, 8:01 AM
Post #1 of 2
(1356 views)
|
"uninitialized value" when I'm certain I initialized it
|
Can't Post
|
|
As my source file's name implies, this is for a college assignment. It's eventually going to draw five cards and give them a score according to poker rules: pair, full house, et al. The relevant bit of code is this:
my (@ranks) = sort($card1{rank}, $card2{rank}, $card3{rank}, $card4{rank}, $card5{rank}); my (%count); for(my $i = 2; $i <=14; $i++){ $count{$i} = 0; print "assigned $count{$i} to $i\n"; } foreach my $item (@ranks) { print "$item $count{$item} "; $count{$item}++; print "$count{$item}\n"; } %count = sort{ $b <=> $a } %count; print "\n$card1{rank}\n"; print "$card2{rank}\n"; print "$card3{rank}\n"; print "$card4{rank}\n"; print "$card5{rank}\n\n"; #while( (my $k, my $v) = each %count){ # print "$k => $v\n"; #} for(my $i = 2; $i <=14; $i++){ print "$i => $count{$i}\n"; } $card1{rank} and the others start with a random integer from 2-14 inclusive. When I run the program, I get this: assigned 0 to 2 assigned 0 to 3 assigned 0 to 4 assigned 0 to 5 assigned 0 to 6 assigned 0 to 7 assigned 0 to 8 assigned 0 to 9 assigned 0 to 10 assigned 0 to 11 assigned 0 to 12 assigned 0 to 13 assigned 0 to 14 10 0 1 10 1 2 5 0 1 6 0 1 8 0 1 10 8 5 10 6 Use of uninitialized value in concatenation (.) or string at assign1.pl line 60. 2 => 3 => 2 Use of uninitialized value in concatenation (.) or string at assign1.pl line 60. 4 => 5 => 4 Use of uninitialized value in concatenation (.) or string at assign1.pl line 60. 6 => 7 => 6 Use of uninitialized value in concatenation (.) or string at assign1.pl line 60. 8 => 9 => 8 Use of uninitialized value in concatenation (.) or string at assign1.pl line 60. 10 => 11 => 10 Use of uninitialized value in concatenation (.) or string at assign1.pl line 60. 12 => 13 => 12 Use of uninitialized value in concatenation (.) or string at assign1.pl line 60. 14 => The first chunk of output tells me that there's values there, but as you can see, later on they're uninitialized. Any tips? Full code is attached.
(This post was edited by Yinyang107 on Dec 6, 2011, 8:03 AM)
|