IB2017 has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Grep match alternative
by pryrt (Abbot) on Oct 11, 2017 at 20:57 UTC | |
by IB2017 (Pilgrim) on Oct 11, 2017 at 21:02 UTC | |
by AnomalousMonk (Archbishop) on Oct 11, 2017 at 21:30 UTC | |
|
Re: Grep match alternative
by karlgoethebier (Abbot) on Oct 12, 2017 at 09:43 UTC | |
|
Re: Grep match alternative
by Anonymous Monk on Oct 11, 2017 at 20:49 UTC | |
by IB2017 (Pilgrim) on Oct 11, 2017 at 21:01 UTC |