rahulme81 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks
I have a directory with a bunch of files. I'm trying to find the latest file created or modified by time in a directory and using the following pattern
*regular*100.0.7.9*failedopendir(my $DIRH, $DIR) or die "Error opening $DIR: $!"; my @files = map { [ stat "$DIR/$_", $_ ] } grep( ! /^\.\.?$/, readdir( $DIRH ) ); #This find me +all files not have dot in directory #How this grep can be accommodate for my regular expre +ssion ????? closedir($DIRH); sub latestFile { $b->[0]->ctime <=> $a->[0]->ctime } my @latest_files = sort latestFile @files; my @latest = @{$latest_files[0]}; my $name = pop(@latest); print "Latest file created fro 100.0.7.9: $name\n";
This is giving the latest file in the directory, but not the file which i need as per my regular expression.
I need to parse the file and do something, which eventually I am able to achieve
Facing difficulty with file name pattern match and get the latest file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Get latest file created or modified & matching part of file name :
by Eily (Monsignor) on Oct 21, 2016 at 14:09 UTC | |
by rinkish85 (Novice) on Oct 21, 2016 at 16:29 UTC |