in reply to checking dates in strings

An alternate approach -- one that makes pesky things like leap years easier to cope with -- is first filter for things that look like dates, then validate them with a separate routine. Something like the following:
s#((\d+)-(\d+)-(\d+))#isDate($2,$3,$4) ? "<date>$1</date>" : $1#e; sub isDate { my($d,$m,$y) = @_; # ... return 1 if these are a valid date, else 0 }
Where isDate() is left as an exercise.

Replies are listed 'Best First'.
Re: Re: checking dates in strings
by Anonymous Monk on Nov 11, 2002 at 00:49 UTC
    cool, that's a good idea, can you just give me a small hint as how to check if say $1 is in the set 10-19 ?
      can you just give me a small hint as how to check if say $1 is in the set 10-19 ?

      Thanks to the outer set of parenthesis, $1 is the complete string matched. It gets substituted for itself if isDate($2,$3,$4) return 0. You can check numbers individually inside of isDate(), where they're available in $d, $m, and $y respectively.

        i am just trying to do this small problem right now
        $brian = 17; if($brian =~ /^1[0-9]$/){ print "$brian is between 10 and 19"; }
        i cannot figure out why this doesn't work. can someone please help?