#!/usr/bin/perl -w use strict; use File::Find; # set these to the desired min and max my $max_depth = 3; my $min_depth = 3; # find files my @files; find({ wanted => sub { my $depth = tr!/!!; # count slashes to get depth return if $depth < $min_depth or $depth > $max_depth; push @files, $_; }, no_chdir => 1 }, '.' ); # sort by mtime @files = sort { (stat($a))[9] <=> (stat($b))[9] } @files; # concat and print foreach my $file (@files) { open FILE, $file or die "Can't open $_ : $!"; while (<FILE>) { print } }
Of course, that's just one way to do it. You could improve it by using a Schwarzian Transform to save time in the sort. Or you could build you script to be called as part of a pipe from the real find.
I suppose it might be nice to teach find2perl to output this trick. Maybe after 5.8.0.
-sam
In reply to Re: find2perl with File::Find and -maxdepth
by samtregar
in thread find2perl with File::Find and -maxdepth
by u914
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |