in reply to
Re^4: Reading every file in a directory
in thread Reading every file in a directory
Hello spookyjack123, and welcome to the Monastery!
I think the following (untested) code will do what you want:
my $current_time = time;
my $old_time = $current_time - (60 * 60 * 24 * 5);
printf "Current time is %d, old time is %d\n", $current_time, $old_tim
my $directory = '/home/gac3/plugins/Essentials/userdata';
for my $YMLfile (<"$directory/*.yml">)
open(my $fh, '<', $YMLfile) or die "Cannot open file '$YMLfile' fo
+r reading: $!";
if (/ ^ \s* login: \s+ ( \d+ ) $ /x)
push @to_delete, $YMLfile if int($1 / 1_000) < $old_time;
close $fh or die "Cannot close file '$YMLfile':
Note that the timestamps in your sample data are 3 digits longer than the output of Perl’s time function. I have simply truncated the timestamp; you may need to adjust this part of the script.
Hope that helps,
Update: Fixed the call to unlink. Thanks to Kenosis for the heads-up!
Athanasius <°(((>< contra mundum