#!/usr/bin/perl use CGI ':standard'; #use CGI::Carp "fatalToBrowser"; $i=param('i'); $i++; print header; $dice1=int(rand(6)+1); $dice2=int(rand(6)+1); #this line is to see if it carries over the $i variable #print "this is $i"; if($i ==1) { $firstroll1=$dice1; $firstroll2= $dice2; } #don't forget to chmod 777 data.txt and 755 dice.cgi if ($i == 1){ open (DICE, ">data.txt")or die print "ERROR $!";; print DICE "$firstroll1 | $firstroll2"; close DICE; }elsif ($i > 1){ open (DICE, "data.txt")or die print "ERROR $!"; while () { ($firstroll1,$firstroll2)=split (/\|/); } close DICE;} print "$firstroll1 and $firstroll2"; print "
"; print "$firstroll1 and $firstroll2"; if (($dice1 + $dice2 ==7) or ($dice1 + $dice2 ==11)) { print "you win"; print "
play again?"; exit() }elsif (($dice1 + $dice2 ==12) or ($dice1 + $dice2 ==2)) { print "you lose"; print "
play again?"; exit() }elsif (($i > 1) and ($dice1 ==$firstroll1) and ($dice2 == $firstroll2)) { print "match"; print "
play again?"; exit() }elsif (($i > 1) and ($dice1 ==$firstroll2) and ($dice2 == $firstroll1)) { print "match"; print "
play again?"; exit() } #print "this is roll number $i"; print "Roll Again?";