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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Looking up elements of an array in another array!
by better (Acolyte) on Mar 14, 2013 at 23:38 UTC | |
by kielstirling (Scribe) on Mar 15, 2013 at 00:18 UTC | |
by Kenosis (Priest) on Mar 15, 2013 at 02:06 UTC | |
by better (Acolyte) on Mar 15, 2013 at 06:49 UTC | |
by 2teez (Vicar) on Mar 15, 2013 at 10:14 UTC | |
by better (Acolyte) on Mar 17, 2013 at 17:08 UTC | |
| |
by better (Acolyte) on Mar 15, 2013 at 21:34 UTC |