Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Always use strict and warnings:

use strict;
use warnings;

They are your friends:

> ./crop.pl Global symbol "$response1" requires explicit package name at ./crop.pl + line 41. Global symbol "$response1" requires explicit package name at ./crop.pl + line 48. Execution of ./crop.pl aborted due to compilation errors.

To get even that far I had to add some "my" statements:

#!/usr/bin/perl use strict; use warnings; print "Content-type: text/html\n\n"; use CGI qw(:standard); my $cornplanted=0; my $cornnotplanted=0; #@number1=("12" .. "25"); #$number1rand=$number1[rand @number1]; my $number1rand=int(rand(20)); my $number2=int(rand(12)); my $correctanswer=($number1rand + $number2); print "$correctanswer <br>"; my $output=<<_html_; <html> <body> <form method="post" action="foodaddition.cgi" name="form2"> Crops planted: $cornplanted <br> <input type="hidden" name="$cornplanted" id="$cornplanted" /> Crops not planted: $cornnotplanted <br> <input type="hidden" name="$cornnotplanted" id="$cornnotplanted" /> What does this math problem equal? <br> $number1rand + $number2 = <input type="text" name="response1" id="resp +onse1" /> <input type="hidden" name="response1" id="response1" /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> _html_ print $output; if ($response1 eq "$correctanswer") { $cornplanted=($cornplanted + 1); print "correct!"; } elsif ($response1 ne "$correctanswer") { $cornnotplanted=($cornnotplanted + 1); print "not correct!"; }

You'll do much better to read the section CREATING FILL-OUT FORMS in the CGI.pm documentation and generate your form fields following proper CGI.pm practice.

To debug your script, follow the recommendations in the DEBUGGING section of the CGI.pm docs.


In reply to Re: having trouble with simple math game by tod222
in thread having trouble with simple math game by mynameisG

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (4)
    As of 2018-07-19 17:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (414 votes). Check out past polls.

      Notices?