http://www.perlmonks.org?node_id=1023570


in reply to Looking up elements of an array in another array!

Here's another option:

use strict; use warnings; my $dir = shift; my $IDs = join '|', map { /(.+)/; "\Q$1\E" } <>; my @results = grep /$IDs/, <$dir/*>; print "$_\n" for @results;

Usage: perl script.pl '/the/dir/to/scan' indexDS.txt [>outFile]

The target directory is (implicitly) shifted off @ARGV and saved for later. The first <> notation reads the index file. map takes each line from the file, and the regex in it matches all characters except the newline. The captured line is surrounded by \Q ... \E to quote any meta-characters in the ID. The results, e.g., "\Q$1\E", are joined with the alternation symbol |, effectively creating an "or" type regex that's used in the grep. A file glob's used to read the directory files and only those names which contain one of the IDs are passed to @results.

Hope this helps!