Ollivier Robert
10/23/2003 12:06:00 PM
In article <rd3fpvc8egjrdt5jd7qh9ncmt5abpakfpi@4ax.com>,
gabriele renzi <surrender_it@remove.yahoo.it> wrote:
> How should I parse a line using a self-defined format?
Here is what I do:
-=-=-
def process_entry (entry)
# Get the ASCII date
#
c_date = entry[-1].sub(/^Canceled on: (.*)$/, '\1')
# Get a hash from the string
#
h_date = Date::strptime(c_date, "%d %b %Y %T %Z")
# Get a Time object
#
n_date = Time.gm(h_date[:year], h_date[:mon], h_date[:mday],
h_date[:hour], h_date[:min], h_date[:sec])
# Check whether we keep the record or not (i.e. older than $num_days)
#
if n_date < ($now - $num_days * SPERDAY)
return true
else
return false
end
end
private :process_entry
-=-=-
Dates are like this:
Canceled on: 21 Mar 2002 21:27:01 GMT
--
Ollivier ROBERT -=- Eurocontrol EEC/ITM -=- roberto@eurocontrol.fr
Usenet Canal Historique FreeBSD: The Power to Serve!