I've written a perl script that is supposed to create a guessing game on the

  • Thread starter Thread starter shannon w
  • Start date Start date
S

shannon w

Guest
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...
 
Back
Top