Hi !
1st : Tell us what you want from this script:
I suppose it's : make someone enter a date until what he/she
types is a "good" date (in "good" format). right ?
If yes, you loop until the entry is OK ?
2nd : the format you show is not clear :
It could be : 2008, January the 1st
2001, January the 8th, ... and so on
It should be better to write it MM-DD-YY (for month, day, year). (FYI
+ :I'm french and we display dates as DD/MM/YY)
for this format, the regex "could" be:
(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])-\d\d
but : it ignores that the maximum number of days depends on the month(
+28,29,30,31), it ignores leap years (February 28th or 29 th ?)
You should use the function "timelocal()" from the standard module
"Time::Local" : try to transform the date you have to validate into a
+n "epoch" time (as the function time() returns) : if the function fai
+ls, the date is wrong :
this script seems to work:
use Time::Local timelocal;
my ($m,$d,$y);
do
{
my $date;
print "date (MM-DD-YY) ? ";
$date=<>;
chomp($date);
($m,$d,$y)=split(/-/,$date);
$m -= 1;
$y += 1900;
}
until(timelocal(0,0,0,$d,$m,$y));
I hope it adresses your need and will help you