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

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.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.