in reply to opening multiple files
You can use glob to find all the file names matching that format. I'll use POSIX::strftime to generarte the glob pattern with today's date. Given the file names, I'll slurp each and count the number of matches to some $re.
use POSIX 'strftime'; my $date = strftime '%Y%m%d', localtime; my $re = qr/whatever/; my $count = 0; for (glob "/path/to/*$date*") { local $/; # to slurp open my $fh, '<', $_ or warn $! and next; my $content = <$fh>; close $fh; $count += () = $content =~ /$re/g; } print $count,$/;
The odd construction where $count is incremented is a common perl idiom for getting a list of matches and counting them. It places the bind-and-match in list context, then the resulting list is evaluated in numeric scalar context. Be cautious about capturing in $re. Multiple captures will produce extra elements in the list.
After Compline,
Zaxo
|
|---|