in reply to force user to only enter numbers

Mastery of the basic command loop is important. This works the same in Java, C, C++, etc.

The basic structure is some sort of a loop that stops when some "quit" or "exit" condition is satisfied. I like to use "while" loops.

Standard reaction when a blank line is input is to just re-prompt - that is not an error.

Standard reaction when blanks occur either before or after the input, is nothing! These extra leading or trailing blanks are not errors.

#!/usr/bin/perl -w use strict; while ( (print "Enter a number: "), (my $number = <STDIN>) !~ /^\s*q(uit)?\s*$/i ) { next if $number =~ /^\s*$/; # re-prompt on blank line if ($number =~ /^\s*[-+]?[0-9]*\.?[0-9]+\s*$/) #a decimal floatin +g point { print "Great! number is: $number\n"; } else { print "illegal number - try again!\n"; } }