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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |