Perl:在指定范围内循环几个月

Hyp*_*vil 2 perl datetime date

我需要在以下范围内指定的所有月份进行循环(foreach):
01-2013到09-2015(月 - 年)格式.
棘手的部分是,在每个循环中我都需要月 - 年数据以及运行SQL查询,所以我不能使用简单的+1计数器.

我看起来像Date :: Calc和Date :: Simple但它没有为我提供解决方案.
有没有人有我可以使用的代码片段或想出如何应对这一挑战的想法?

TLP*_*TLP 7

日期时间模块有一个很好的功能,add它允许您添加要对象的任何时间量:

use strict;
use warnings;
use DateTime;
use feature 'say';

my $start = DateTime->new(year => 2013, month => 1);
my $end   = DateTime->new(year => 2015, month => 9); 

while ($start <= $end) { 
    $start->add(months => 1); 
    say $start->strftime("%m-%Y"); 
}
Run Code Online (Sandbox Code Playgroud)