Good morning moesplace,
as I have to admit that I just overread a part of your requirement I got the feeling that I'm in dept showing a building block for another way of solving your issue. Some other Monks gave different advices and hints. Mine here is a little different as it uses DateTime and DateTime::Duration to explicitly loop over every day in between your start and end date. So, probably another way to look at your problem. And definitely a Perlish solution showing regexes, using top rated modules, operator overloading:
#!/usr/bin/perl use strict; use warnings; use DateTime; use 5.010; die "ERROR: You have to provide start- and end-date in format 'YYYYMMD +D'" if @ARGV != 2; my $start_date = $ARGV[0]; my $end_date = $ARGV[1]; my $start_year = 1900; my $start_month = 01; my $start_day = 01; my $end_year = 2100; my $end_month = 01; my $end_day = 01; if($start_date =~ m/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$/) + { $start_year = $1; $start_month = $2; $start_day = $3; } else { die "ERROR: Start Date doesn't match YYYYMMDD"; } if($end_date =~ m/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$/) { $end_year = $1; $end_month = $2; $end_day = $3; } else { die "ERROR: End Date doesn't match YYYYMMDD"; } my $start = DateTime->new( year => $start_year, month => $start_month, day => $start_day, ); my $end = DateTime->new( year => $end_year, month => $end_month, day => $end_day, ); if($end < $start) { die "ERROR: end date is less than start date."; } my $one_day = DateTime::Duration->new(days => 1); for(my $i = $end; $i >= $start; $i -= $one_day) { my $output = sprintf('%04d%02d%02d', $i->year, $i->month, $i->day, ); say $output; # Check if path exists # chdir to it # do what you want # chdir back }
Best regards
McA
UPDATE: The driver in this solution are the generated dates and not the files found which than get compared to the start- and end-date.
In reply to Re^2: processing dates as directories
by McA
in thread processing dates as directories
by moesplace
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |