friar tux has asked for the wisdom of the Perl Monks concerning the following question:
hi, I am trying to save the first variable in a random number generator for comparison against later numbers generated my problem is it won't retain the first number it generates can some one tell me why? here is the script index.html
<html> <center> <img src=./pix/submit.jpg> <hr> <form action=/cgi-bin/dice.cgi method=post> <a href= cgi-bin/dice.cgi?roll=1 >roll the dice</a> </center> </html>
then it goes to the dice.cgi script
#! /usr/bin/perl use CGI ':standard'; print "Content-type:html\n\n"; $dice1= int (rand(6)+1); $dice2= int (rand(6)+1); $match = param('match'); $roll = param ('roll'); print "<img src=http://localhost/pix/die$dice1.gif>"; print "<img src=http://localhost/pix/die$dice2.gif>"; if ($roll== 1) { } $rolla = $dice1 ; $rollb = $dice2 ; $total= $dice1+$dice2; print "$rolla"; print "$rollb"; print "$total"; if ($total ==7) { print "lucky seven"; print "<a href= http://localhost/>play again</a>" ; exit() } elsif ($total ==11) { print "eleven wins"; print "<a href= http://localhost/>play again</a>" ; exit() }elsif ($total ==2) { print "snake eyes"; print "<a href= http://localhost/>play again</a>" ; exit() }elsif ($total ==12) { print "double six"; print "<a href= http://localhost/>play again</a>" ; exit() } print "<a href= dice.cgi>roll again</a>"
I know I can write it to an outside text file but that doesn't seem efficient any ideas on how to retain the two $dice numbers for the first roll then compare them after to each roll after?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: saving a random number while generating a new one
by JavaFan (Canon) on Mar 30, 2011 at 14:15 UTC | |
|
Re: saving a random number while generating a new one
by jethro (Monsignor) on Mar 30, 2011 at 14:19 UTC | |
by friar tux (Novice) on Mar 30, 2011 at 17:17 UTC | |
|
Re: saving a random number while generating a new one
by Sinistral (Monsignor) on Mar 30, 2011 at 14:38 UTC | |
by raybies (Chaplain) on Mar 30, 2011 at 15:13 UTC | |
|
Re: saving a random number while generating a new one
by locked_user sundialsvc4 (Abbot) on Mar 30, 2011 at 18:07 UTC | |
|
Re: saving a random number while generating a new one
by fidesachates (Monk) on Mar 30, 2011 at 14:51 UTC |