hasnainzeenwala has asked for the wisdom of the Perl Monks concerning the following question:
open FILE, "high_score.dat"; while (1){ while defined($score = <FILE>){ print "$score\n"; } $num = int(1 + rand 100); print "If you want to exit type 'quit' or 'exit' or leave a blank +line\n"; INPUT_TAKER: { $count++; print "Guess a num: "; chomp ($guess = <STDIN>); if ($guess == $num) { print "Right!!!.\n"; print "enter youre name: "; chomp($name = <STDIN>); while defined ($line = (<FILE>)){ if ($line =~ /^($name)/){ $line =~ s/\d+$/$count/; } else{ open FILE, ">>high_score.dat"; print FILE "$name has the score of $count\n"; } } print "You took $count chances to complete\n"; } elsif ($guess =~ /^(exit||quit||\n)$/){ last; } elsif ($guess > $num){ print "High!!!. Go lower \n"; redo INPUT_TAKER; } elsif ($guess < $num){ print "Low!!!. Go higher \n"; redo INPUT_TAKER; } } if ($guess =~ /^exit||quit||\n$/){ last; } } print "Thank you for playing my game\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Random numbers and substitution
by ig (Vicar) on May 31, 2011 at 09:07 UTC | |
|
Re: Random numbers and substitution
by Marshall (Canon) on May 31, 2011 at 09:19 UTC | |
by JavaFan (Canon) on May 31, 2011 at 10:05 UTC | |
|
Re: Random numbers and substitution
by GrandFather (Saint) on May 31, 2011 at 21:11 UTC |