Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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 ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: smart glob of dated subfolders
by LanX (Saint) on Feb 22, 2023 at 20:28 UTC | |
|
Re: smart glob of dated subfolders
by Corion (Patriarch) on Feb 22, 2023 at 20:18 UTC | |
by Anonymous Monk on Feb 25, 2023 at 11:35 UTC | |
|
Re: smart glob of dated subfolders
by cavac (Prior) on Feb 27, 2023 at 18:00 UTC | |
by tybalt89 (Monsignor) on Feb 27, 2023 at 22:23 UTC | |
by cavac (Prior) on Feb 28, 2023 at 07:12 UTC | |
|
Re: smart glob of dated subfolders
by Anonymous Monk on Feb 23, 2023 at 10:19 UTC | |
by Anonymous Monk on Feb 23, 2023 at 15:41 UTC |