Internet Marketing Business Forum


Internet Marketing Business Forum » MAIN FORUMS » Web Design & Programming » I've written a perl script that is supposed to create a guessing game on the web I...
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.

Reply
 
LinkBack Thread Tools Display Modes
Old 08-01-2009, 08:45 AM   #1 (permalink)
 shannon w's Avatar
 
Status: Junior Member
Join Date: Jul 2009
Posts: 1
shannon w is on a distinguished road
Default I've written a perl script that is supposed to create a guessing game on the web I...

...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...
shannon w is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 08-01-2009, 10:45 AM   #2 (permalink)
 sterno73's Avatar
 
Status: Junior Member
Join Date: Aug 2009
Posts: 1
sterno73 is on a distinguished road
Default

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.
sterno73 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Reply
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 09:12 AM.
Powered by vBulletin® Version 3.7.0 Beta 6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.


Nav Item BG