#!/usr/bin/perl -w use strict; my $magic = int (rand 100 ); my $guesses = 1; my $line; print "Guess a number between 0-99\n"; while ( (print "Enter an integer: "), $line = <STDIN>, $line !~ /^\s*q(uit)?\s*$/i ) { next if $line =~ /^\s*$/; #re-pompt on blank line if ( $line !~ /^\s*(\d{1,2})\s*$/ ) { print "Illegal entry! Try again!\n\n"; next; } print "Too high!\n\n" if $1 > $magic; print "Too low!\n\n" if $1 < $magic; last if $1 == $magic; $guesses++; } print "You got it right in $guesses guesses! \n" if ($line !~ /^\s*q(uit)?\s*$/i);
In reply to Re^2: Modifying loop structure and placement
by Marshall
in thread Modifying loop structure and placement
by irvson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |