First use the grep() function to get the .txt files:
Code:
opendir(DIR2, $directory) or die "Can't open $directory: $!";
@files = grep {/\.txt$/i} readdir(DIR2);
closedir(DIR2);
Actually -C was wrong, it is -M for the modification date. You have to use the sort{} function to sort the file to know which is the most recently modified:
Code:
my $directory = '//TESTINGSQL/memorandum_export/log/';
opendir(DIR2, $directory) or die "Can't open $directory: $!";
@files = grep {/\.txt$/i} readdir(DIR2); #get txt files only
closedir(DIR2);
@sorted = sort {-M "$directory$a" <=> -M "$directory$b"} @files; #sort them by modification date most recent to least recent
print "The most recent modified file is: $sorted[0]";