| Web Design & Programming Building websites, coding scripts or developing apps? html, css, javascripts, ajax, php, asp, java, c+, C++ and other geeky info is here. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| Status: Junior Member Join Date: Jul 2009 Posts: 1
![]() | ...could use some help? HERE IS MY CODE #!/usr/local/bin/perl print "Content-type: text/html\n\n"; use CGI qw/:standard/; print_header; print start_html('Guessing Game'), start_form, "Guess a Number!",textfield('guess'), p, submit, end_form, hr; $guesses = 0; $a = int(rand(100))+1; while () { print "\nEnter a number from 1 to 100: "; $guess = <STDIN>; chomp $guess; $guesses++; if ($guess == $a) { print "Random Number: $a\n"; print "Number of Guesses: $guesses\n"; next; } elsif ($guess > $a) { print "Too high\n"; next; } else { print "Too low\n"; last; } } print end_html; The page shows up but the form doesn't work it prints out too low, and doesn't let any numbers be submitted... |
| | |
| | #2 (permalink) |
| Status: Junior Member Join Date: Aug 2009 Posts: 1
![]() | The issue is that you are not getting the guess from the web form. You have coded as if the user is interacting directly with the script, which is not the case. The interaction is happening through the web page, so when the user submits the form, the script has to get the user input from the form. I'm including a link to a tutorial for cgi programming in Perl. |
| | |
![]() |
| Thread Tools | |
| Display Modes | |
| |