Um, about your sample data... I hope that isn't really what you have to cope with, because Dec. 5 2004 was a Sunday, not a Saturday. (And I hope you'll have at least some actual data that falls within the last 45 days, else what would be the point of a script that applies that threshold?)

As for your problem, if you look at the docs for the first module suggested in the first reply, and just play with Date::Manip in the simplest possible experiment, I think you'd get what you want. For example (replacing your bad sample data with some relevant data):

#!/usr/bin/perl use strict; use Date::Manip; my $limit = DateCalc( 'now', '- 45 days' ); while (<DATA>) { my $datestr = (split / : /)[0]; # note spaces around ":" print if ( ParseDate( $datestr ) > $limit ); } __DATA__ Fri Dec 3 23:07:21 EST 2004 : Depth is : 234 Sat Dec 4 00:07:29 EST 2004 : Depth is : 123 Sat Feb 26 14:13:12 EST 2005 : Depth is : 4567

In reply to Re: grep for last 45 days by graff
in thread grep for last 45 days by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.