in reply to Appropriately assigning times to variables

I think the approach went astray before line 1 and the logic looks to be in reverse order from what I'd have done.

A sensible first step (suggested in what is left hanging at the end of your code) is to convert the current time to a format that matches the directories, before doing anything with them at all (i.e. why read them into an array unfiltered - put all the filtering in one place and process in a grep/readdir loop without needing an array...)

Update: added comments in Filter subroutine as requested by OPer

# convert current time to same format as dirs my $now; { my @now = localtime(); $now = $now[5]+1900; $now[4]++; for ( my $i = 4; $i > 1; $i-- ) { $now .= '_'; $now[$i] = "0$now[$i]"; $now[$i] = substr( $now[$i], -2 ); $now .= $now[$i]; } } # get only those directories that match requirements: my $dir = "parent-of-directories"; opendir my $dh, $dir or die $!; for my $file ( grep Filter( now => $now, dir => $dir ), readdir $dh ) +{ my $path = "$dir/$file"; # and go right ahead and process the directory "$path" here in the +loop # ... # } closedir $dh; sub Filter { # put all filter conditions here ... my %opt = @_; ( -d "$opt{ dir }/$_" ) # is a directory && !/^\./ # is also not hidden/special && /(\d{4}_\d{2}_\d{2}_\d{2})/ # contains date/hour && ($opt{ now } gt $1 ) # that is in the past ; }
__________________________________________________________________________________

^M Free your mind!

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.