On Wed, Jan 9, 2013 at 10:11 AM, Bill Stephenson <[email protected]>wrote:
> date=11/01/2003
>
> I want to trap bad data sent to time::local in a loop where I use these
> lines:
>
> my ($date_month, $date_day, $date_year) = split(/\//,
> $DOCUMENT->param("date"));
>
> $date_year = ($date_year-1900);
> $date_month = ($date_month-1);
>
> my $test_date = timelocal($sec, $min, $hours, $date_day,
> $date_month, $date_year);
>
I'm allowing "01-01-2013" too
my $date_str = $DOCUMENT->param("date");
if ( $date_str and $date_str = m#(\d+)[/-](\d+)[/-](\d+)# ) {
my ($date_month, $date_day, $date_year) = ($1, $2, $3);
...
}
else {
warn("bad date: $date_str");
}
You should always parse user input to get exactly what you want (digits)
and not use their input directly. You should probably check (if it's an
text input and not a pick list, say) that you have a 4 digit year etc.
--
a
Andy Bach,
[email protected]
608 658-1890 cell
608 261-5738 wk