Re: Perl: "find -newer" in nativ

Andreas Fett <[email protected]>
Newsgroups gmane.user-groups.linux.dresden
Message-ID <[email protected]>
Hallo,

On Sat, Feb 11, 2023 at 12:50:20PM +0100, Hilmar Preuße wrote:
> Moin,
> 
> voran: ich bin ein absoluter Perl Noob und bin darum wahrscheinlich auch
> 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`;
> 
> In $touchfile findet sich der Name meines Referenz-Files. Ich bin mir
> sicher, das kann man auch nativ in Perl machen. Bitte um Hilfe.

---- snip ----
#!/bin/perl
#
use warnings;
use strict;

use File::stat;
use File::Find;
use Data::Dumper;

my $touchfile = 'ref.txt';

my $touchstat = stat($touchfile) or die "No $touchfile: $!";

my @files = ();
my $wanted = sub {
        my $stat = stat($_);
        push @files, $File::Find::name if -f $stat && $stat->mtime > $touchstat->mtime; # TODO check name
};

find($wanted, glob("/path/to/pen8*/pools/*/logf"));

print Dumper(@files);
---- snip ----

Den Match für den Filenamen bekommste selber hin :-)

https://perldoc.perl.org/File::Find
https://perldoc.perl.org/perlrequick

viel Spass.

Grüsse
Andreas
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEJ6Jq1qpfVQ9CLff4NMc/tuPtDEAFAmPntecACgkQNMc/tuPt
DEAqow/+I9JZl+u7ggGzrh2d4q0daXmU0NJ4gQBictrz6ZgX3c1/HBtxSWYDg65S
OCCKIUqGIV97/5hTBwJ69WXkZ8DOoMdegbuNSt3WMTGR2YwrPrDbc6XTlGDT8+bn
V/WdosplB5Oz+VfMMdVUToJ6YH9snEoWw03cUIBKWkqHtb7gOr+cr03aklsue1mn
PIiwEWT7ZiI2dWZ6dihmKVir+XlVoQC1axB/duuT7x1k+szFcw+jNDIy2iDmed0o
7XD6opW0l3ncRxNLqt4g7Ks219VJUXcqQMDqfrtNRk51l/NC6dBzkJVwNCSxQCOj
EcxckF3/RWTY73fyR/grThjct54chrKZXsGv6gxz0P2UaDRd+eiCwr7/3nj667Mz
JIR0ORSDeTPJ6cN6qjSVhUbNqDrpXnXTFZ8qTqIKTYgrrSf5cIwH+5W6aM/6ibMY
hjpPQ7bXfEJgUl/fzp03hv0THqKAJTLS17xV07llR+nR442dCwMRDIgYb1LzdcQf
qTp0Jt6FhzlLbtb783iBRo7UJ/hv0L2oDxyMLY09/01JvkU2O6G86RQZBILtI6VD
GQyeTskevpSlGLHjrzRiscmcptrgpF7qvDwpI8Ryo4yscC5SiYKr3cHTzcrkE1xy
/VTbChDg3vatr6jy+rzlor1KHlm/T8vbjDn6iNwikCCDeQ7RyDI=
=P5fi
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.