From: Alexander Foken <[EMAIL PROTECTED]>
> [EMAIL PROTECTED] wrote:
> > Lo all,
> >
> > Which is faster for checking that user input is numeric, using the
> > look_like_number function or a compiled regex? The number in
> > question is a positive 4 digit integer.
> >
> I think you can beat /^\d{4}$/ only by using a carefully crafted piece
> of C code. > Which would be faster if I also had to check that the
> number was > in 24hr clock format? > ie one regex to do that or
> looks_like_number followed by another > regex? >
>
> Like above: /^\d{2}:\d[2}$/ without seconds, /^\d{2}:\d[2}:\d{2}$/
> with seconds. Note that those REs do not check the values, 99:99 would
> be accepted as a valid 24h clock value. To check the values, do
> something like this:
>
> $value=~/^(\d{2}):(\d[2}):(\d{2})$/ or die "not 24h format";
> $1<24 or die "invalid hour value";
> $2<60 or die "invalid minute value";
> $3<60 or die "invalid second value"; # 62 if you are pedantic and want
> to accept leap seconds
$value =~ /^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/
or die "not 24h format";
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery