I'm having problems with a perl script I'm working on for some course work.
The script asks for a four digit number before going onto the next part of the script.
The problem is I need the script to only accept a four digit number but whatever I try I can usually get it to accept three figures and sometimes five or more figures.
I've tried using the IF statement, the WHILE statement, the UNTIL, DO WHILE, etc....but still I can't solve this problem.
Here is the script using an if statement:
#!c:\perl\bin\perl.exe
print("Enter your four digit customer reference number.\n");
$ref=<STDIN>;
if ($ref !~ m/[0-9]{4}/)
{
print("Not a valid number, please enter your correct customer reference number.\n");
$ref=<STDIN>;
}
Can anyone help me?
Dave
The script asks for a four digit number before going onto the next part of the script.
The problem is I need the script to only accept a four digit number but whatever I try I can usually get it to accept three figures and sometimes five or more figures.
I've tried using the IF statement, the WHILE statement, the UNTIL, DO WHILE, etc....but still I can't solve this problem.
Here is the script using an if statement:
#!c:\perl\bin\perl.exe
print("Enter your four digit customer reference number.\n");
$ref=<STDIN>;
if ($ref !~ m/[0-9]{4}/)
{
print("Not a valid number, please enter your correct customer reference number.\n");
$ref=<STDIN>;
}
Can anyone help me?
Dave