Hilmar Preuße <hill...@web.de> (Sa 11 Feb 2023 12:50:20 CET):
> Moin,
> zu doof, google zu bedienen (nein bei ChatGPT war ich noch nicht). Ich
> suche in einer Directory Structur eine Liste von Files, die aktueller
> sind als ein Referenz-File. Aktuell mache ich das so:
> 
> my @files1 = `find /path/to/pen8*/pools/*/logf -type f -newer $touchfile
> -name "Psipenta_*.log" 2> /dev/null`;

Das wäre meine Variante:

```
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use File::FnMatch 'fnmatch';

my $touchfile = shift // die "need name of touchfile\n";
my @dirs = @ARGV or die "need directories\n";

sub newer {
        my $files = shift;
        my $ref = -M shift;
        my $pattern = shift;
        return sub {
                return unless fnmatch $pattern, $_; # name is cheap
                return unless -f;                   # implies a stat, may be 
expensive
                return if -M _ > $ref;              # "_" uses stat cache
                push @$files, $File::Find::name;
        }
}

my @files;
find(newer(\@files, $touchfile, "*.log"), @dirs);
print join "\n", @files;
```

-- 
Heiko

Attachment: signature.asc
Description: PGP signature

Antwort per Email an