<?xml version="1.0" encoding="windows-1252"?>
<node id="996877" title="Re^3: Search array of file names in directory structure" created="2012-10-02 12:05:19" updated="2012-10-02 12:05:19">
<type id="11">
note</type>
<author id="965102">
Kenosis</author>
<data>
<field name="doctext">
&lt;p&gt;Here's the line, explained a bit:&lt;/p&gt;
&lt;c&gt;
my $regex = join '|', map "\Q$_\E?", @filelist;
                  ^         ^ ^ ^^
                  |         | | ||
                  |         | | |+ - Last character in file name optional, i.e., the "l" in html
                  |         | | + - End quote metacharacters
                  |         | + - The default scalar aliased to each @filelist element
                  |         + - Begin quote metacharacters (e.g., the period)
                  + - Join each element with alternation ("or") character
&lt;/c&gt;
&lt;p&gt;As shown, this results in the following:&lt;/p&gt;
&lt;c&gt;
1234567_3a_20101000\.html?|99877_b_20111111\.html?|99877_c_20111111\.html? ...
&lt;/c&gt;
&lt;p&gt;This line builds a regex using the file names in &lt;c&gt;@filelist&lt;/c&gt;.  When passed to &lt;c&gt;File::Find::Rule&lt;/c&gt; as the &lt;c&gt;-name&lt;/c&gt; rule, only those files names which match the regex will be returned by &lt;c&gt;File::Find::Rule&lt;/c&gt;, if any.&lt;/p&gt;
&lt;p&gt;If you want &lt;c&gt;File::Find::Rule&lt;/c&gt; to look for a particular pattern, change the regex here:&lt;/p&gt;
&lt;c&gt;
-&gt;name(qr/^(?:$regex)$/)
          ^^^^^^^^^^^^
&lt;/c&gt;
&lt;p&gt;However, if you want to process the files returned by &lt;c&gt;File::Find::Rule&lt;/c&gt;, you can do something like this:&lt;/p&gt;
&lt;c&gt;
my @matchingFileNames = grep /pattern/, @found_html;
&lt;/c&gt;
&lt;p&gt;where "pattern" represents the regex that would 'filter' the elements of &lt;c&gt;@found_html&lt;/c&gt;.&lt;/p&gt;</field>
<field name="root_node">
996672</field>
<field name="parent_node">
996873</field>
</data>
</node>
