in reply to Re: Using user input to return variable typed.
in thread Using user input to return variable typed.
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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using user input to return variable typed.
by davido (Cardinal) on Nov 13, 2012 at 16:13 UTC | |
|
Re^3: Using user input to return variable typed.
by thmsdrew (Scribe) on Nov 13, 2012 at 16:01 UTC | |
by myelinviolin (Novice) on Nov 13, 2012 at 16:21 UTC |