I wonder how you generate your list of files.
Using the glob function enables you to use a finename mask giving you only the files matching this mask. This makes thing easier For example:
my @file_list = glob "./mypath/CHECK*.txt";This filters out all filenames that do not start with CHECK and end with .txt. Note that, in this case, the "CHECK*.txt" string is not a Perl regex, it is an operating system file matching pattern (meaning inter allia that, here, the * stands for any group of characters and that you don't have to escape the dot). The glob function has the additional advantage that it will return you a list of files with their relative path, which is usually handy if you need to fo further work on these files.
This glob function is quite practical, but this will not solve the issue of the files that you want to exclude, but you are not stating clearly the rules for exclusion (just one example is definitely not a spec). Assuming for the sake of example that having a second underscore in the name is a reason for exlusion, you could do this in one go as follows:
my @file_list = grep {! /_.*_/} glob "./mypath/CHECK*.txt";This single line above replaces the opendir and readdir statements and the regexes on the file names. (The regex in the grep block is not particularly efficient and can be improved if needed but it is just given as a very simple example.)
In reply to Re: how to check whether a particular word exists in filename
by Laurent_R
in thread how to check whether a particular word exists in filename
by learner@perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |