Dear monks
I need to read the files contained in a directory and select them according to their extensions. I'd like to use grep as it seems to be a very fast and concise solution, but I am having problems in matching more than one extention at a time. How can improve the following (it doesn't produce any result, the problem being in the regexp in combination with grep)?
opendir (DIR, "$MyDir") or die "$!"; my @Documents = grep {/\.[docx|pdf]$/} readdir DIR; my $number_of_files = scalar @Documents; print "Total number of files found in folder: $number_of_files +\n"; close DIR;
In reply to Grep match alternative by IB2017
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |