0: # Howdy! This is my very first Perl script! I know it's kinda short
1: # but any response would be great. What I am trying to do next is to make
2: # it in a CGI/HTML format to put on a web page. Hints anyone?
3:
4:
5:
6: #!/usr/local/bin/perl -w
7:
8: print "Guess the number.";
9: print "DIRECTIONS:\nGuess a number between 1 and 100 inclusive.\n\n";
10: $random = int(rand(100)+1); # I added 1 to the random
11: # number generator to push the
12: # possible numbers from 0-99 to 1-100
13:
14: for ($try=6;$try>0;$try--){ # $try is the number of tries you get (DUH!)
15: print "You have 1 try left. Use it wisely!\n\n" if($try ==1);
16: print "You have $try tries left.\n\n" if($try !=1);
17: print "What is your guess? -->";
18: do {
19: $guess = <STDIN>; chomp $guess;
20:
21: }while (!$guess);
22: print "HA! HA! too HIGH.\n" if ($guess>$random);
23: print "OH! NO! too LOW.\n" if ($guess<$random);
24: if ($guess==$random){
25: print "'Bout time you guessed it. Stupid head.\n\n" ;
26: exit;
27: }
28: }
29: print "The answer was $random. And so is your IQ.\n\n\nSTUPID!!\n\n";
30: exit;
31:
32:
33: ############################################################
34: # UPDATED --- 1/11/03 #
35: # NOTE: the problem with this is that it loops #
36: # printing the button text box ect. w/o giving you a #
37: # chance to guess. Still a work in progress. #
38: # Any generous monk out there willing to give me a #
39: # little nudge? #
40: ############################################################
41:
42:
43:
44: #!/usr/local/bin/perl -w
45:
46: print "Content-type: text/html\n\n";
47: use CGI;
48: $query = new CGI;
49: print "<HTML><HEAD><title>Guess the number.</title></HEAD><BODY>";
50: print "<H1>DIRECTIONS:\nGuess a number between 1 and 100 inclusive.\n\n</H1>";
51: $random = int(rand(100)+1);
52:
53: for ($try=6;$try>0;$try--){
54: print "You have 1 try left. Use it wisely!\n\n" if($try ==1);
55: print "You have $try tries left.\n\n" if($try !=1);
56: print "What is your guess? -->";
57: print '<INPUT TYPE="text" NAME="guess">';
58: print '<INPUT TYPE = "submit">';
59: print "HA! HA! too HIGH.\n" if ($guess>$random);
60: print "OH! NO! too LOW.\n" if ($guess<$random);
61: if ($guess==$random){
62: print "'Bout time you guessed it. Stupid head.\n\n" ;
63: print"</BODY>";
64: exit;
65: # print "The answer was $random. And so is your IQ.\n\n\nSTUPID!!\n\n";exit;
66: }
67: }
68: print "The answer was $random. And so is your IQ.\n\n\nSTUPID!!\n\n";
69: print"</BODY>";
70: exit;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|