perl file help

jmoney3457jmoney3457 Maine
edited November 2007 in Internet & Media
i got 3 .pl files coming over from html file..and everything working fine except it the 3rd pl file won't display the info i need it to..its basically a dice game (called crap lol) & the 3rd pl file is suppose to print out the # of wins, losses & the persons name when you hit the end button but its not printing any of those 3 and i can't find the needed code to take out or put in the game is located @ http://ctech.smccme.edu/~petersons/cgi-bin/crap.html and the code for the 3 pl files are as follows:
crap1.pl
#!/usr/bin/perl
use CGI ':standard';
print "content-type: text/html\n\n";

$player=param('name');
$dice1=int(rand(6)+1);
$dice2=int(rand(6)+1);
$win=param('win');
$lose=param('lose');


$point=$dice1+$dice2;

print" Your first die was a $dice1<br><br> <img src=images/$dice1.gif><br><br>";
print" Your second die was a $dice2<br><br> <img src=images/$dice2.gif><br><br>";

print " Your roll was $point<br><br>";

if (($point == 7) || ($point == 11)){
        ++$win;
        print"You win, play again?";
        print"<form method=post action=crap.pl>
                <input type=hidden name=win value=$win>
                <input type=submit value=Play>
                </form>";
        }
elsif (($point == 2) || ($point == 3) || ($point == 12)){
        ++$lose;
        print" You lose, play again?";
        print"<form method=post action=crap.pl>
                <input type=hidden name=lose value=$lose>
                <input type=submit value=Play>
                </form>";
        }

else{
        print"Your point is $point";
        print"<form method=post action=crap2.pl>
                <input type=hidden name=name value=$name>
                <input type=hidden name=name value=$name>
                <input type=hidden name=win value=$win>
                <input type=hidden name=lose value=$lose>
                <input type=hiddin name=point value=$point>
                <input type=submit value=Roll></form>";
}
crap2.pl
#!/usr/bin/perl
use CGI ':standard';
print "content-type: text/html\n\n";


$player=param('name');
$point=param('point');
$win=param('win');
$lose=param('lose');

$dice1=int(rand(6)+1);
$dice2=int(rand(6)+1);

$shoot=$dice1+$dice2;

print" Your first die was a $dice1<br><br> <img src=images/$dice1.gif><br><br>";
print" Your second die was a $dice2<br><br> <img src=images/$dice2.gif><br><br>";

print " Your roll was $shoot<br><br>";

if ($shoot == 7){
        ++$lose;
        print"You lose, play again?<br><br>
                <form method=post action=crap.pl>
                <input type=hidden name=name value=$name>
                <input type=hidden name=win value=$win>
                <input type=hidden name=lose value=$lose>
                <input type=submit value=Roll></form>
                <form method=post action=crap3.pl>
                <input type=hidden name=name value=$name>
                <input type=hidden name=win value=$win>
                <input type=hidden name=lose value=$lose>
                <input type=submit value=End>
                </form>";

}
elsif ($shoot == $point){
        ++$win;
        print"You win, play again?<br><br>
       <form method=post action=crap.pl>
        <input type=hidden name=name value=$name>
        <input type=hidden name=win value=$win>
        <input type=hidden name=lose value=$lose>
        <input type=submit value=Roll></form>
        <form method=post action=crap3.pl>
        <input type=hidden name=name value=$name>
        <input type=hidden name=win value=$win>
        <input type=hidden name=lose value=$lose>
        <input type=submit value=End>
        </form>";


}
else{
        print"
        <form method=post action=crap2.pl>
        <input type=hidden name=name value=$name>
        <input type=hidden name=win value=$win>
        <input type=hidden name=lose value=$lose>
        <input type=submit value=Roll></form>";
}
crap3.pl
#!/usr/bin/perl
use CGI ':standard';
print "content-type: text/html\n\n";

print"$name , you won $win times and lost $lose times. This has been written to a file.";

$filename= "score.txt";
$name=param('name');
$win=param('win');
$lose=param('lose');



open(DATAFILE,">> $filename");
print DATAFILE "|$name|$win|$lose|\n";
close(DATAFILE);
anyone know which code in crap3 need to add or remove...its got to be something in crap 3 not outputting the # wins/losses & name correctly

Comments

  • kryystkryyst Ontario, Canada
    edited November 2007
    This is just some guesses.

    In the 3rd line of code your are calling your print statement before you define your parameters.

    Also on the print datafile do you need brackets around it like in the open and close lines?
  • jmoney3457jmoney3457 Maine
    edited November 2007
    yep..we got it to work..thanks kry
Sign In or Register to comment.