I think your algorithm is a little more complex than necessary. I'd do something like this:

#!/usr/bin/perl -w use strict; use Time::Local; # Get the epoch time and the day of the week my $now = time; my $dow = (localtime($now))[6]; # Get the various elements of the current date and time, # subtracting the correct number of seconds to move to # the previous Sunday. # N.B. 86_400 is the number of seconds in a day my @time = localtime($now - ($dow * 86_400)); # Move to the previous midnight @time[0 .. 2] = (0, 0, 0); # Get the epoch seconds. This is now the # start of the previous Sunday my $sunday = timelocal(@time[0 .. 5]); # Add a day to get to the start of the previous # Monday my $monday = $sunday + 86_400; # At this point you can do what you want with this # number - maybe use it in the where clause of # a database query. print scalar localtime $monday;
--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me


In reply to Re: There's More Than One Way To Do It by davorg
in thread There's More Than One Way To Do It by DarkBlue

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.