Here's an option:
use strict; use warnings; my $directory = '.'; for my $YMLfile (<"$directory/*.yml">) { open my $fh, '<', $YMLfile or die $!; while (<$fh>) { # process the file's contents } close $fh; }
Update: Perhaps I've misunderstood your issue. In one place you say that you want the files "...to be opened so the timestamp may be read...," as if the timestamp may be a string within the file. Yet, at the beginning, you mention a script that can "...check the age of over 20,000 YML files..." In the latter case files are not opened. If it's the latter case, the following may assist you:
use strict; use warnings; use File::stat; my $directory = '.'; my $currentTime = time; for my $YMLfile (<"$directory/*.yml">) { my $mtime = stat($YMLfile)->mtime; print "$YMLfile: " . ( $currentTime - $mtime ) . " seconds old\n"; }
You can also try the -M operator on the files, which returns the file's age in days:
for my $YMLfile (<"$directory/*.yml">) { print -M $YMLfile, "\n"; }
And the following PM node may be helpful: How do I find and delete files based on age?.
I strongly suggest running your file-deleting script on a practice directory.
In reply to Re^3: Reading every file in a directory
by Kenosis
in thread Reading every file in a directory
by spookyjack123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |