Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: New to Perl: Hashes and int(rand())

by davido (Cardinal)
on Jun 14, 2014 at 06:42 UTC ( [id://1089873]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1089873]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found