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?
In reply to saving a random number while generating a new one by friar tux
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |