G'day moesplace,

Welcome to the monastery.

The basic tools you need for this are the readdir & reverse functions and the .. operator used as a flip-flop. Here's some skeleton code to show the technique:

#!/usr/bin/env perl -l use strict; use warnings; my $base_dir = './pm_proc_dir_dates_rev_dir'; my $start_date = '20110228'; my $end_date = '20110302'; opendir my $dh, $base_dir or die "Can't open '$base_dir': $!"; for (reverse grep { /^[^.]/ } readdir $dh) { if (/$end_date$/ .. /$start_date$/) { print "+ Processing: $base_dir/$_"; } else { print "- Skipping: $base_dir/$_"; } } closedir $dh;

Output:

$ pm_proc_dir_dates_rev.pl - Skipping: ./pm_proc_dir_dates_rev_dir/20110303 + Processing: ./pm_proc_dir_dates_rev_dir/20110302 + Processing: ./pm_proc_dir_dates_rev_dir/20110301 + Processing: ./pm_proc_dir_dates_rev_dir/20110228 - Skipping: ./pm_proc_dir_dates_rev_dir/20110227

Here's a listing of the ./pm_proc_dir_dates_rev_dir directory:

$ ls -1a ./pm_proc_dir_dates_rev_dir . .. 20110227 20110228 20110301 20110302 20110303

-- Ken


In reply to Re: processing dates as directories by kcott
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.