The order of sorting is O(nlgn) (I think perl uses quicksort). Finding the
maximum or minimum in a list can be done
in O(n) time. This being the case sorting the files by age is not the best
solution.

All that needs to be done here glob through the directory (perldoc -f glob) and
apply the -A or -M or -C operator
to get the age (perldoc -f -x). The code for this would be

#!/usr/local/bin/perl -w
use strict;

my $dirname = shift || '.';
if (!-d $dirname) {
        die "$dirname : No such file or directory\n";
}
my $lat_file;

while (glob ("$dirname/*")) {
        $lat_file = $_ if (!defined ($lat_file) || -A $_ < -A $lat_file);
}

if (defined ($lat_file)) {
        print "latest_file is $lat_file\n";
}

$lat_file will contain the latest file in the directory.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to