Well, the main problem is that you declare a new instance of the handN variables inside your if{} blocks, and so the values of those variables die when they go out of scope (once the if block ends). Then you revert back to the previous (undefined) value of $hand1, $hand2, etc.
Update: Notice also that the warnings you received were pretty good clues to the source of the problem:
Use of uninitialized value in addition (+) at ./test.pl line N, <> lin
+e M.
The line in question was this line:
my $teamhand=$hand1 + $hand2 + $hand3 + $hand4;
So it is saying that you are adding up variables that you have never initialized. Sure enough, when you originally declared them, you didn't set them to zero or anything. But surely you updated their value along the way, didn't you? Ah, no, that's when I noticed the new 'my' declaration of each of the $hand1, $hand2, $hand3 and $hand4 variables.
No good deed goes unpunished. -- (attributed to) Oscar Wilde
|