in reply to Get newest file

If you mean newest as in time of modification, then you can do something like this:
my ($newest) = sort { -M $b <=> -M $a } glob("*");
Although untested, this is basically how you approach this sort of thing.

Replies are listed 'Best First'.
Re^2: Get newest file
by Aristotle (Chancellor) on Oct 27, 2002 at 21:14 UTC

    That will stat all files more than once (remember, sort is N*log(N)), and will, particularly for large directories, break down horribly in performance. The least you can do here is a Schwartzian Transform or variant thereof.

    Also remember that globbing for * will miss any files starting with a dot - if that is of significance.

    I'd do something like this:

    my ($age, $name) = (0, ""); opendir DIR, $directory; while(my $curname = readdir DIR) { my $curage = (stat "$directory/$curname")[9]; next unless -f _; ($name, $age) = ($curname, $curage) if $curage > $age; } closedir DIR;
    But that still doesn't address the recursive nature of the original poster's task. Zaxo makes the right points.

    Makeshifts last the longest.