Hi Monks,

I have a directories A, B, etc that contain dated subfolders in chronological order (YYYYMMDD format) and I am using glob to find ONLY the subfolders in the future. I cannot assume anything about the dates (i.e. how far into the past or future). This function, however, has become quite slow over time, so I am looking for a way to speed it up. I call this function quite often, so I'd like to make it as fast possible. I need to keep the history of dated folders, so deleting subfolders is NOT a solution.

It seems pointless to search through the entire history when I just need the future dates, so I'm looking for a way to glob ONLY the future dates. Maybe I can use readdir instead of glob in some smart way?

Below is a simplified version of my code. I apologize for any mistakes !!

################################################### ## folders + dated subfolders There are many !! ## A/<date1> = past ## A/<date2> = future ## B/<date3> = past ## B/<date4> = future ## .. ## function needs to return [ <date2>,A and <date4>,B ] ###################################################
sub _isGoodFolder { my ($theDate,$datePlusFolder,$attr) = @_; my ($date) = ($datePlusFolder =~ /\/(\d{8})$/); if ($date > $theDate) { ## compare folder date with today return $datePlusFolder; } return ''; } my $today = new Date::Business->image; my $dir = <basePath>; my $cwd = Cwd::getCwd(); chdir($dir); my @folderKeys = grep { _isGoodFolder($today,$_) } glob("*/*"); chdir($cwd); return [ map { join ",",(split "\/")[1,0] } @folderKeys ];

In reply to smart glob of dated subfolders by Anonymous Monk

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.