perlcraft
chip_creep
# Howdy! This is my very first Perl script! I know it's kinda short
# but any response would be great. What I am trying to do next is to make
# it in a CGI/HTML format to put on a web page. Hints anyone?
#!/usr/local/bin/perl -w
print "Guess the number.";
print "DIRECTIONS:\nGuess a number between 1 and 100 inclusive.\n\n";
$random = int(rand(100)+1); # I added 1 to the random
# number generator to push the
# possible numbers from 0-99 to 1-100
for ($try=6;$try>0;$try--){ # $try is the number of tries you get (DUH!)
print "You have 1 try left. Use it wisely!\n\n" if($try ==1);
print "You have $try tries left.\n\n" if($try !=1);
print "What is your guess? -->";
do {
$guess = <STDIN>; chomp $guess;
}while (!$guess);
print "HA! HA! too HIGH.\n" if ($guess>$random);
print "OH! NO! too LOW.\n" if ($guess<$random);
if ($guess==$random){
print "'Bout time you guessed it. Stupid head.\n\n" ;
exit;
}
}
print "The answer was $random. And so is your IQ.\n\n\nSTUPID!!\n\n";
exit;
############################################################
# UPDATED --- 1/11/03 #
# NOTE: the problem with this is that it loops #
# printing the button text box ect. w/o giving you a #
# chance to guess. Still a work in progress. #
# Any generous monk out there willing to give me a #
# little nudge? #
############################################################
#!/usr/local/bin/perl -w
print "Content-type: text/html\n\n";
use CGI;
$query = new CGI;
print "<HTML><HEAD><title>Guess the number.</title></HEAD><BODY>";
print "<H1>DIRECTIONS:\nGuess a number between 1 and 100 inclusive.\n\n</H1>";
$random = int(rand(100)+1);
for ($try=6;$try>0;$try--){
print "You have 1 try left. Use it wisely!\n\n" if($try ==1);
print "You have $try tries left.\n\n" if($try !=1);
print "What is your guess? -->";
print '<INPUT TYPE="text" NAME="guess">';
print '<INPUT TYPE = "submit">';
print "HA! HA! too HIGH.\n" if ($guess>$random);
print "OH! NO! too LOW.\n" if ($guess<$random);
if ($guess==$random){
print "'Bout time you guessed it. Stupid head.\n\n" ;
print"</BODY>";
exit;
# print "The answer was $random. And so is your IQ.\n\n\nSTUPID!!\n\n";exit;
}
}
print "The answer was $random. And so is your IQ.\n\n\nSTUPID!!\n\n";
print"</BODY>";
exit;