in reply to greping from lists
You can read the parent directory:
my $dir = "whatever"; local *DIR; my $file; my $newest; my $path; opendir(DIR, $dir) or die "Failed to open $dir: $!\n"; while (defined($file = readdir(DIR))) { $path = "$dir/$file"; if ( (-d $path) && ($file =~ /^PC/) ) { $newest = $path if ( !defined($newest) || ((stat($path))[9] > (stat($newest))[9]) ); } } closedir(DIR); chdir($newest);
This may be easier using File::Find and I'd probably turn it into a callable sub in either case.
|
|---|