in reply to Oldest file using -M

If all files in the directory are newer than the beginning of the script execution, you'll get no results. That's why you shouldn't initialize your "oldest" to 0, but rather to the first element of the array, if any:
my @names = glob "*" or die "Nothing to scan"; my $oldest_name = shift @names; my $oldest_age = -M $oldest_name; for (@names) { # remaining names if (-M > $oldest_age) { $oldest_name = $_; $oldest_age = -M _; } } printf "%s is %.2d days old\n", $oldest_name, $oldest_age;
Why does this look familar? Why, it's one of our Llama exercises!

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Oldest file using -M
by Gerard (Pilgrim) on Apr 27, 2004 at 20:40 UTC
    Ok, well that clears things up a great deal. Makes sense too. Just going to give it a test now....Thanks all for your replies.

    Regards, Gerard

    Update: Tested - Perfect! Thanks