RE: [PBML] Figuring up dates - age
- First, you may want to use the "unpack" function to extract the date (year,
month and day separately) from the record.
As for dealing with time, the Perl core functions include "time" and
Returns the number of non-leap seconds since whatever time the system
considers to be the epoch (that's 00:00:00, January 1, 1904 for MacOS, and
00:00:00 UTC, January 1, 1970 for most other systems). Suitable for feeding
to gmtime and localtime.
Converts a time as returned by the time function to a 9-element list with
the time analyzed for the local time zone.
Since you are just interested in dates, read the date, break into year,
month and date, and then multiply out. Then multiply by seconds in a day,
and you can subsequently do the math using these and other Perl modules.
$aDay = 60 * 60 *24; # seconds in a day
To save yourself a LOT of effort and get a bunch of extra functionality,
look at the "Date" module. If using ActiveState, "This module is not
included with the standard ActivePerl distribution. It is available as a
separate download using PPM."
If not using ActiveState, you may need to go to http://cpan.org/ and get the
Date module (Date-Calc-...). See
for more info.
A few of the included functions are:
use Date::Calc qw(
BY THE WAY:
If this is a business application, the end users (Accounting perhaps?) will
typically run something like this at a particular time of month, like
"beginning of month" or "end of month". AND, at least once or twice a year,
something *will* go wrong, and the report will need to be re-run. In that
case, make sure you can override today's date with the original date of the
> -----Original Message-----
> From: ericvia@... [mailto:ericvia@...]
> Sent: Thursday, January 04, 2001 6:01 PM
> To: email@example.com
> Subject: [PBML] Figuring up dates - age
> cut -c131-140 FILENAME | grep 200011* | wc -l
> echo "Records were found for November 2000"
> cut -c131-140 FILENAME | grep 200012* | wc -l
> echo "Record were found for December 2000"
> Now as you can see that'll do it - but what I would LIKE to do is
>be able to produce an output of:
>"437 records are older than 30 days"
>"937 records are older than 60 days"
>"23 records are older than 90 days"
> Can anyone give me any pointers? Do you think there's something in
> PERL I could use to do this??
I have printed your post for reference - it's a lot to digest not
knowing much of Perl (yet) - so I'll be looking it over and trying
your suggestions - I'm sure I'll run into glitches but I'll persevere.
Thank you SO VERY MUCH!!!!
> BY THE WAY:perhaps?) will
> If this is a business application, the end users (Accounting
> typically run something like this at a particular time of month,like
> "beginning of month" or "end of month". AND, at least once or twicea year,
> something *will* go wrong, and the report will need to be re-run.In that
> case, make sure you can override today's date with the originaldate of the
> report.It's run every day - each morning. Right now there's a C-program
that does it - but not knowing much of C I want to look into if I
could also have it done in Unix.
Thanks SO MUCH and have a super weekend!