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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.