Chas Owens wrote: > On 9/10/07, Mathew Snyder <[EMAIL PROTECTED]> wrote: >> I have a script which has to be manually edited to run for a span of days. >> When >> these days are over several weeks it can be clearly tedious to enter dates in >> yyyy-mm-dd format. I've decided to set it up to ask for user input. >> >> What I need is some input on is how to make it create the array for all the >> dates requested. For instance, if someone wants to run the script spanning >> 07/20/2007 to 08/20/2007 how can I split that up to ensure it runs across all >> days and both months? >> >> I'm thinking I would have to split each argument into an array and then >> create >> an array for the months and days running a foreach loop over them both. But >> then, how would I accommodate the varying number of days in each month? > snip > > Take a look at the DateTime modules. > > #!/usr/bin/perl > > use strict; > use warnings; > use DateTime; > > my %start; @start{qw<month day year>} = split /\//, shift; > my %end; @end{qw<month day year>} = split /\//, shift; > > my $cur = DateTime->new(%start); > my $end = DateTime->new(%end); > > while (DateTime->compare($cur, $end) < 1) { > print $cur->strftime("%Y-%m-%d\n"); > $cur->add(days => 1); > } > > [EMAIL PROTECTED]:~$ perl t.pl 09/10/2007 09/24/2007 > 2007-09-10 > 2007-09-11 > 2007-09-12 > 2007-09-13 > 2007-09-14 > 2007-09-15 > 2007-09-16 > 2007-09-17 > 2007-09-18 > 2007-09-19 > 2007-09-20 > 2007-09-21 > 2007-09-22 > 2007-09-23 > 2007-09-24 > > snip >> Any input will be appreciated. Thanks. > snip >
Thanks. But I'm confused by > my %start; @start{qw<month day year>} = split /\//, shift; > my %end; @end{qw<month day year>} = split /\//, shift; What's happening here? Mathew -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/