[comp.lang.perl] date-pattern-matching question

rahardj@ccu.umanitoba.ca (Budi Rahardjo) (05/27/91)

I need advice to perform date pattern matching.
Suppose I have the following text file :
----- text.file ----
# userid|name|creator|creation date|expiry date|deletion date
#
user01|name1|me|date11|date12|date13
user02|joe bloe|someone else|date21|date22|date23
user03|...
... etc.
----- end of text.file ----

I'd like to perform the following queries :
- get userid that was created before certain date (or month, or year)
- get userid that was supposed to be terminated but not deleted 
- get userid that has name=x and created before datex
- .. etc.
ie date-comparison operations

1. How would you store the date ? Which format ?
   dd-mm-yy
   dd/mm/yy
   or integer number (ie # of days since 1980)
   or even May 27 11:49:31 CDT 1991

2. How would you do the actual pattern matching ?
   Example needed ...
   (BTW, the actual database has 50 fields and stored as dbm file).


Thanks,
budi

--
``A system without PERL is like a hockey game without a fight.''
                                -- Mitch Wright

clewis@ferret.ocunix.on.ca (Chris Lewis) (05/28/91)

In article <1991May27.165523.2644@ccu.umanitoba.ca> rahardj@ccu.umanitoba.ca (Budi Rahardjo) writes:
>I need advice to perform date pattern matching.

>I'd like to perform the following queries :
>- get userid that was created before certain date (or month, or year)
>- get userid that was supposed to be terminated but not deleted 
>- get userid that has name=x and created before datex
>- .. etc.
>ie date-comparison operations

>1. How would you store the date ? Which format ?
>   dd-mm-yy
>   dd/mm/yy
>   or integer number (ie # of days since 1980)
>   or even May 27 11:49:31 CDT 1991

yymmdd.  Then you can do either numeric or lexical string comparisons to find
out "before", "after" or "same".  Incrementing dates in this format is "hardish",
but not too hard.

>2. How would you do the actual pattern matching ?
>   Example needed ...
>   (BTW, the actual database has 50 fields and stored as dbm file).

something like:
    foreach key (keys(database)) {
	(name, field2, field3...) = split(/<something>/, $database{$key});
	if (name eq 'fred' && date < 910213) {
	...

Etc.  There's probably much faster ways (grep?)
-- 
Chris Lewis, Phone: (613) 832-0541, Domain: clewis@ferret.ocunix.on.ca
UUCP: ...!cunews!latour!ecicrl!clewis; Ferret Mailing List:
ferret-request@eci386; Psroff (not Adobe Transcript) enquiries:
psroff-request@eci386 or Canada 416-832-0541.  Psroff 3.0 in c.s.u soon!