<?xml version="1.0" encoding="windows-1252"?>
<node id="316415" title="Guess the number" created="2003-12-22 12:10:48" updated="2005-08-13 01:00:11">
<type id="121">
perlcraft</type>
<author id="315452">
chip_creep</author>
<data>
<field name="doctext">
#   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&gt;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? --&gt;";
    do {
        $guess = &lt;STDIN&gt;; chomp $guess;

     }while (!$guess);
    print "HA! HA! too HIGH.\n" if ($guess&gt;$random);
    print "OH! NO! too LOW.\n" if ($guess&lt;$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 "&lt;HTML&gt;&lt;HEAD&gt;&lt;title&gt;Guess the number.&lt;/title&gt;&lt;/HEAD&gt;&lt;BODY&gt;";
print "&lt;H1&gt;DIRECTIONS:\nGuess a number between 1 and 100 inclusive.\n\n&lt;/H1&gt;";
$random = int(rand(100)+1);

for ($try=6;$try&gt;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? --&gt;";
    print '&lt;INPUT TYPE="text" NAME="guess"&gt;';
    print '&lt;INPUT TYPE = "submit"&gt;';
    print "HA! HA! too HIGH.\n" if ($guess&gt;$random);
    print "OH! NO! too LOW.\n" if ($guess&lt;$random);
    if ($guess==$random){
        print "'Bout time you guessed it.   Stupid head.\n\n" ;
        print"&lt;/BODY&gt;";
        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"&lt;/BODY&gt;";
exit;
</field>
</data>
</node>
