in reply to New to Perl: Hashes and int(rand())
The reason it prints three times is that you moved the "print" statement into the loop's body, so on each loop iteration, it prints. Unfortunately, since you modified the HERE doc, you can't just move the print outside of the loop, because the $true variable won't be in scope. Even if it were in scope, it would print the same value for strength, intelligence, and dexterity, since it only contains one value.
The easiest solution is to revert to the template that the book gave you (namely, the HERE doc should look like this:
print <<"END"; Strength: $stat_for{strength}
...and so on). Once you've made that change, you can change this line:
$true = $randvalue + $randv2;
...to this...
$stat_for{$stat_name} = $randvalue + $randv2;
Dave
|
|---|