Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
    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;
    

In reply to Guess the number by chip_creep

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (9)
    As of 2014-09-22 15:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (198 votes), past polls