Dates are easy. Either you want to find all the records relative to the current date (next 30 days, for instance), in which case you can just store a timestamp with each record and then check that timestamp against the current timestamp:
my $mtime = time();
if ($rtime < $mtime + 86400 * 30) {
## Do whatever processing
}
Or you want to find all records within an exact date range, in which case you just store the dates in fixed-width, greatest significance first numerical format and test as necessary:
use strict;
use warnings;
my ($sdate, $edate, $rdate);
$sdate = sprintf('%04d%02d%02d', 2006, 11, 4);
$edate = sprintf('%04d%02d%02d', 2006, 12, 4);
while (<DATA>) {
($rdate) = m/(\d+)/;
print if $sdate <= $rdate && $rdate <= $edate;
}
__DATA__
20061203 Record 1
20061204 Record 2
20061206 Record 3
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.