in reply to Re^4: read write from a file
in thread read write from a file
Cool, here's a few suggestions
Here's a quick clean up of your code with the above suggestions:
#!/usr/bin/perl use CGI ':standard'; use CGI::Carp "fatalsToBrowser"; use strict; use warnings; my $i = 1 + (param('i') || 0); my $firstroll1 = param('roll1'); my $firstroll2 = param('roll2'); print header; my $dice1 = 1 + int rand 6; my $dice2 = 1 + int rand 6; print "($i) $dice1, $dice2<br>"; if (!$firstroll1 || !$firstroll2) { $firstroll1 = $dice1; $firstroll2 = $dice2; my $sum = $dice1 + $dice2; if ( $sum == 7 || $sum == 11 ) { print "you win"; print qq{<hr><a href="dice.cgi">play again?</a>}; exit; } elsif ( $sum == 2 || $sum == 12 ) { print "you lose"; print qq{<hr><a href="dice.cgi">play again?</a>}; exit; } } else { if ($dice1 == $firstroll1 && $dice2 == $firstroll2 ) { print "match"; print qq{<hr><a href="dice.cgi">play again?</a>}; exit; } elsif ($dice1 == $firstroll2 && $dice2 == $firstroll1 ) { print "match"; print qq{<hr><a href="dice.cgi">play again?</a>}; exit; } } print qq{<a href="dice.cgi?i=$i&roll1=$firstroll1&roll2=$firstroll2">R +oll Again?</a>};
|
|---|