<?xml version="1.0" encoding="windows-1252"?>
<node id="348807" title="Multiple regex against files with speed" created="2004-04-28 09:06:41" updated="2005-06-24 04:56:36">
<type id="115">
perlquestion</type>
<author id="319416">
crabbdean</author>
<data>
<field name="doctext">
Hi Fellow Monks and Nuns,&lt;br&gt;&lt;br&gt;

I'm rewriting a perl module to do file listing because quite frankly I don't like File::Find.  I've got it listing beautifully, its fast and in OO.  I want to now add features.  One is to be able to specify types of files or directories to match against.&lt;br&gt;&lt;br&gt;

In essence you have to be able to specify many types of files (eg. ~*.doc, ~*.tmp etc).  It then has to check each file against ALL these types.  Simply I want to know, what is the fastest way of doing this?&lt;br&gt;&lt;br&gt;

So far I'm considered:&lt;br&gt;
1.  Storing the regex string into the values of hashes and then doing a regex against each of the search hash values.
&lt;CODE&gt;
$found = 0;
$hash{1} = '*.doc';
$hash{2} = '*.xls';
$hash{3} = '*.ppt';
map {
     $found = 1 if $file =~ /$_/;
} values(%hash);
&lt;/CODE&gt;&lt;br&gt;
2.  OR stringing all the searchstrings together into one big regex
&lt;CODE&gt;
$found = 0;
$hash{1} = '*.doc';
$hash{2} = '*.xls';
$hash{3} = '*.ppt';
for (values(%hash)) {
     $string .= $_ . "|";
}
$found = 1 if $file =~ /$string/;
&lt;/CODE&gt;

Any other ideas?  Speed is the key here.  Thanks.&lt;br&gt;&lt;br&gt;

Oh, and if you have any other requests for what you'd like in this module or frequent types of things you do against files in your scripts, I'll see what I can do to add them in.
&lt;div class="pmsig"&gt;
&lt;div class="pmsig-319416"&gt;
&lt;br&gt;
[id://319416|Dean]&lt;br&gt;
The Funkster of Mirth&lt;br&gt;
&lt;i&gt;&lt;small&gt;Programming these days takes more than a lone avenger with a compiler. - sam&lt;br&gt;
[http://www.ietf.org/rfc/rfc1149.txt|RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers
]&lt;/i&gt;&lt;/small&gt;
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
