You may want to look at the glob() function to get the list of files, such as:
# Assumes filenames of the form *yyyymmdd.txt my $filepattern = sprintf("*%d%d%d.txt", 1900+(localtime)[5], 1+(localtime)[4], (localtime)[3]); foreach my $filename (glob($filepattern)) { # Process individual files herein }
As to finding the count of the number of times the expression is found, perhaps something along the lines of:
# Looking, for instance, for "/usr/.*/?bin/perl" my $regex = qr{(/usr/.*/?bin/perl)}gs; my ($line); { open(DF, $filename) or die("Can't open $filename for input: $!\n"); my @lines = <DF>; close(DF); $line = join('', @lines); } my @matches = $line =~ m/$regex/; printf "Filename: %40s Occurrances: %9d\n", $filename, scalar @matches;
Hope that helps.
Update: 19 Dec 2004 - Added values for sprintf function in first code section
In reply to Re: opening multiple files
by atcroft
in thread opening multiple files
by sandeep
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |