A solution using the, core since 5.10, Time::Piece module and its associated Time::Seconds for date arithmetic. I accept the strftime() default format for brevity but you could craft the output any way you like.
johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -MTime::Piece -MT
+ime::Seconds -E '
my $ffJan = Time::Piece->strptime( q{2020/01/01}, q{%Y/%m/%d} );
$ffJan += ONE_DAY for 1 .. 5 - $ffJan->day_of_week();
my $end = Time::Piece->strptime( q{2020/06/01}, q{%Y/%m/%d} );
while ( $ffJan->epoch() < $end->epoch() )
{
say $ffJan->strftime();
$ffJan += ONE_WEEK;
}'
Fri, 03 Jan 2020 00:00:00 UTC
Fri, 10 Jan 2020 00:00:00 UTC
Fri, 17 Jan 2020 00:00:00 UTC
Fri, 24 Jan 2020 00:00:00 UTC
Fri, 31 Jan 2020 00:00:00 UTC
Fri, 07 Feb 2020 00:00:00 UTC
Fri, 14 Feb 2020 00:00:00 UTC
Fri, 21 Feb 2020 00:00:00 UTC
Fri, 28 Feb 2020 00:00:00 UTC
Fri, 06 Mar 2020 00:00:00 UTC
Fri, 13 Mar 2020 00:00:00 UTC
Fri, 20 Mar 2020 00:00:00 UTC
Fri, 27 Mar 2020 00:00:00 UTC
Fri, 03 Apr 2020 00:00:00 UTC
Fri, 10 Apr 2020 00:00:00 UTC
Fri, 17 Apr 2020 00:00:00 UTC
Fri, 24 Apr 2020 00:00:00 UTC
Fri, 01 May 2020 00:00:00 UTC
Fri, 08 May 2020 00:00:00 UTC
Fri, 15 May 2020 00:00:00 UTC
Fri, 22 May 2020 00:00:00 UTC
Fri, 29 May 2020 00:00:00 UTC
I hope this is helpful.
Update: It makes more sense to calculate the cut-off epoch once at the start rather than every loop.
johngg@shiraz:~/perl/Monks$ perl -Mstrict -Mwarnings -MTime::Piece -MT
+ime::Seconds -E '
my $endEpoch = Time::Piece->strptime( q{2020/06/01}, q{%Y/%m/%d} )->ep
+och();
my $ffJan = Time::Piece->strptime( q{2020/01/01}, q{%Y/%m/%d} );
$ffJan += ONE_DAY for 1 .. 5 - $ffJan->day_of_week();
while ( $ffJan->epoch() < $endEpoch )
{
say $ffJan->strftime();
$ffJan += ONE_WEEK;
}'
Fri, 03 Jan 2020 00:00:00 UTC
Fri, 10 Jan 2020 00:00:00 UTC
Fri, 17 Jan 2020 00:00:00 UTC
Fri, 24 Jan 2020 00:00:00 UTC
Fri, 31 Jan 2020 00:00:00 UTC
Fri, 07 Feb 2020 00:00:00 UTC
Fri, 14 Feb 2020 00:00:00 UTC
Fri, 21 Feb 2020 00:00:00 UTC
Fri, 28 Feb 2020 00:00:00 UTC
Fri, 06 Mar 2020 00:00:00 UTC
Fri, 13 Mar 2020 00:00:00 UTC
Fri, 20 Mar 2020 00:00:00 UTC
Fri, 27 Mar 2020 00:00:00 UTC
Fri, 03 Apr 2020 00:00:00 UTC
Fri, 10 Apr 2020 00:00:00 UTC
Fri, 17 Apr 2020 00:00:00 UTC
Fri, 24 Apr 2020 00:00:00 UTC
Fri, 01 May 2020 00:00:00 UTC
Fri, 08 May 2020 00:00:00 UTC
Fri, 15 May 2020 00:00:00 UTC
Fri, 22 May 2020 00:00:00 UTC
Fri, 29 May 2020 00:00:00 UTC
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.