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;
"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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |