gibsonvc
asked on
Perl - Looping while statements - Enter valid dates
I'm attempting to write a perl script with two looping while statements that prompts a user for information such as the effective starting and ending dates for a promotion. Since this information is going to be used to edit an xml file I need this information in the format of %4d-%02d-%02d (with the hyphens). Below is my first attempt at this, which I can't figure out why it does not work:
print "Please enter the effective start date for this promotion.\n";
print "Enter a date numerically: yyyy-mm-dd\n";
print "example 2005-12-31\n";
$startdate = <STDIN>;
chomp $startdate;
while ($startdate ne /^([0-9]{4})\/([0-12]{2})\ /([0-31]{2 })$/){
print "Invalid Entry. Please try again.\n";
$startdate = <STDIN>;
}
print "Please enter the expiry date for this promotion.\n";
print "Enter a date numerically: yyyy-mm-dd\n";
print "example 2005-12-31\n";
$enddate = <STDIN>;
chomp $enddate;
while ($enddate ne /^([0-9]{4})\/([0-12]{2})\ /([0-31]{2 })$/){
print "Invalid Entry. Please try again.\n";
$enddate = <STDIN>;
}
Any information is greatly appreciated!
print "Please enter the effective start date for this promotion.\n";
print "Enter a date numerically: yyyy-mm-dd\n";
print "example 2005-12-31\n";
$startdate = <STDIN>;
chomp $startdate;
while ($startdate ne /^([0-9]{4})\/([0-12]{2})\
print "Invalid Entry. Please try again.\n";
$startdate = <STDIN>;
}
print "Please enter the expiry date for this promotion.\n";
print "Enter a date numerically: yyyy-mm-dd\n";
print "example 2005-12-31\n";
$enddate = <STDIN>;
chomp $enddate;
while ($enddate ne /^([0-9]{4})\/([0-12]{2})\
print "Invalid Entry. Please try again.\n";
$enddate = <STDIN>;
}
Any information is greatly appreciated!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what entries is it not accepting?
your print saays to use - between numbers but your expression looks for /
ASKER
Thank you, it works now!
ASKER
I have changed the ne to !~ but it still will not allow accept valid or invalid entries!?!?