Learning Perl here..  So I wrote this number guessing script but can't see 
what is wrong with it.  I can never get the solution even when I know it's 
correct.  What am I doing wrong?

#!/usr/bin/env perl

use Math::Random;
use strict;

sub run(){
  my $solution = random_uniform_integer(1, 1, 100);
  my $guess = undef;
  do {
    print "\$solution = $solution\n";
    print "Guess (1 - 100) ?\n";
    chomp(my $guess = <STDIN>);
    if ($guess > $solution) {
      print "$guess is too HIGH!\n";
    }
    if ($guess < $solution) {
      print "$guess is too LOW!\n";
    }
  } while ($guess != $solution);
  print "$guess is correct, YAY!\n";
  print "Play again? ";
  chomp(my $answer = <STDIN>);
  if (lc($answer) eq 'y') {
    run();
  }
}

run();


TIA :)

-- 
Greg Donald
[EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to