in reply to processing dates as directories

Maybe this could also help.
I would rather take the start and end from the CLI and check if they are correct.
See if this can help:

#!/usr/bin/perl -w use strict; use Getopt::Long; GetOptions( 'directory=s' => \my $directory, 'start_date=s' => \my $start, 'end_date=s' => \my $end, ); die 'Unknown directory path' unless defined $directory; opendir DIRH, $directory or die "can't open directory :$!"; my @files = grep { -d && $_ ne '.' && $_ ne '..' } readdir(DIRH); closedir DIRH or die $!; @files = file_range( files => \@files, begin => $start, end => $end, ); for (@files) { # do whatsoever you want in here # to each of the directory, you might have to # use subroutrine chdir, then opendir # over to you print $_, $/; } sub file_range { my %data = @_; my $file_size = 0; # check if the dates each has date in full i.e 4 digit 20110910 $file_size += split //, $_ for $data{begin}, $data{end}; #== 16 +; die 'One or both of your start or end date is not correct ' unless $file_size == 16; my @files_to_return; for my $file ( sort { $b <=> $a } @{ $data{files} } ) { push @files_to_return => grep /$file/, $data{begin} .. $data{e +nd}; } return @files_to_return; }
To run so: script.pl -directory . -start 20110219 -end 20120303 Where '.' is your directory, you can as well change that.