### Comment on

 Need Help??
I think I mostly figured out the hash thing. (The answer is always hashes, isn't it!) Thanks guys! BUT for instance I have a variable called CMB, for example, that uses a dice rolling subroutine, that gives me random numbers before the hash. (Can you tell what I'm doing? :P) I'm having a problem with this giving me the same dice roll every time. Let's say A = 14 because I rolled a 14. But, after this value goes in the hash, it gets stuck at 14. So if I want to be able to stay in the program and keep typing in numbers, I will always get a 14 for A. Before it goes in the hash, I can keep getting new numbers for the rolls, but I want to get new numbers afterwards as well. Any help for this?
``` sub roll{
my (\$a)=@_;
#chop(\$a);
(\$b,\$constant)=split(/\+|\-/,\$a);
(\$number,\$dice)=split(/[dD]/, \$b);
if (\$constant==''){
\$constant=0;
}
if(\$a=~ m/\-/){
\$constant*=(-1);
}
\$count=0;
for (\$c=1; \$c<=\$number; \$c++){
\$d[\$c]=int(rand(\$dice))+1;
\$count += \$d[\$c];
}
\$count += \$constant;
if (\$count<0){
\$count=0;
}
return "\$count";
}

\$A=roll("1d20");
\$B=roll("1d20");
\$C=roll("1d20");

print "BEFORE HASH:\$A\t\$B\t\$C\n";

%hash= (
A => "\$A",
B => "\$B",
C => "\$C",
);

print "What would you like to know?\n\n";

\$type=<STDIN>;
chomp(\$type);

until (\$type eq "Q"){

#print "You typed .\$type.\n";

print "\n\n\$type: \$hash{\$type}\n";

print "What would you like to know?\n\n";
\$type=<STDIN>;
chomp(\$type);
}

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
 [stevieb]: Torturing one of my dev RPis to turn four 5v stepper motors at the same time (via Parallel:: ForkManager for 50k degrees (a whole lot of full turns!). Let's see if it burns out or not. [stevieb]: My GPIO expander chips should arrive tomorrow, but I think I'll throw a shift register against them and see if all six I have will turn at once. Amps are near the breaking point, but I want to know max sustainable V and I output.

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-03-22 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (286 votes). Check out past polls.

Notices?