not quite:
The idea is to create one age and one name for each subdirectory. This grouping can be done by a hash. However you should use the "grouping-criteria" as hash-key.
In your case it is $File::Find::dir. The rest of your logic can remain unchanged.
use strict;
use warnings;
use File::Find;
@ARGV = ('.') unless @ARGV;
my %age;
my %name;
sub oldest {
return if ((defined $age{$File::Find::dir}) && ($age{$File::Find::di
+r} < (stat($_))[9]));
$age{$File::Find::dir} = (stat(_))[9];
$name{$File::Find::dir} = $File::Find::name;
}
find(\&oldest, @ARGV);
foreach my $n (keys(%age))
{
print $name{$n}." " . scalar(localtime($age{$n})) . "\n";
}
btw.: I'm unsure whether this is a homework-question or not ... if it is be sure that you totally understand the solution. I have seen many situations
where a student couldn't explain some code supposedly written by himself. You don't want that happen to you! ;-)
Rata |