Tested under WinNT:

use strict; use Date::Tie; tie my %dt, 'Date::Tie'; my @a; for (1..7) { push @a, join('-', $dt{year}, $dt{month}, $dt{day}); $dt{day}--; } my $re = join('|', @a); for ( qw( 2003-08-25 2003-08-20 2003-08-27 2003-08-15 ) ) { print "$_ is "; print "not " unless /$re/; print "in last 6 days\n"; } # 2003-08-25 is in last 6 days # 2003-08-20 is in last 6 days # 2003-08-27 is not in last 6 days # 2003-08-15 is not in last 6 days

update: "full version":

use strict; use Date::Tie; tie my %dt, 'Date::Tie'; my @a; for (1..7) { push @a, join('-', ( $dt{day} < 10 ? "(?:0)?".(0+$dt{day}) : $dt{day} ), ( $dt{month} < 10 ? "(?:0)?".(0+$dt{month}) : $dt{month} ), "(?:".substr($dt{year}, 0, 2).")?".substr($dt{year}, 2, 2) , ); $dt{day}--; } my $re = join('|', @a); print "RE: $re\n"; for ( qw( 25-08-2003 25-8-03 20-08-03 27-08-2003 15-8-03 ) ) { print "$_ is "; print "not " unless /$re/; print "in last 6 days\n"; } # 25-08-2003 is in last 6 days # 25-8-03 is in last 6 days # 20-08-03 is in last 6 days # 27-08-2003 is not in last 6 days # 15-8-03 is not in last 6 days

In reply to Re: Week Algorithm by fglock
in thread Week Algorithm by rupesh

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.