Alex Rivera | Logout

What is the optimal way to loop between two dates in Perl?

Asked 2011-07-08T09:57:16.917
18

What is the optimal/clearest way to loop between two dates in Perl? There are plenty of modules on CPAN that deal with such matter, but is there any rule of thumb for iterating between two dates?

Edit
Report

1 Answer

1

I think the "best" way to do that depends a lot on what you're doing between these two days.

In many cases, a simple for (0..31) loop will suffice.

In other cases, you may wish to use an epoch value, and add/subtract 86400 seconds on each itteration.

In one application I've written, I do exactly this, using a DateTime object that I add one day to for each iteration. This is likely overkill for many applications, though.

answered 2011-07-08T10:07:29.100

Your Answer