Hi,
I eschew Time::Piece for date math. It has some weird internal issues with constants and overloading, which I don't completely understand, but people I trust including some wiser and more experienced Monks than I, recommend against it. (See e.g. comments in this discussion.)
Alternate solution using Time::Moment which IIUC is as accurate as DateTime but considerably lighter-weight:
use v5.10;
use Time::Moment;
my $tm1 = Time::Moment->new(year => '2019', month => '6', day => '1');
my $tm2 = Time::Moment->now;
$tm1 = (say $tm1->strftime('%c') and $tm1->plus_months(1)) while $tm1
+<= $tm2;
Output:
Mon Jul 1 00:00:00 2019
Thu Aug 1 00:00:00 2019
Sun Sep 1 00:00:00 2019
Tue Oct 1 00:00:00 2019
Fri Nov 1 00:00:00 2019
Sun Dec 1 00:00:00 2019
Wed Jan 1 00:00:00 2020
Hope this helps!
The way forward always starts with a minimal test.
-
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.
|