Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Search array of file names in directory structure

by kennethk (Monsignor)
on Oct 01, 2012 at 17:34 UTC ( #996698=note: print w/ replies, xml ) Need Help??


in reply to Re: Search array of file names in directory structure
in thread Search array of file names in directory structure

If you are going for an autogenned regex off a fixed file list, why bother with the grouping? By the time you've gotten to the file extension, you've already passed the more rigorous constraint. Plus, yours can fail positive due to substring match and your filter doesn't allow for checking .htm files, as in the original regex. Simpler and more recyclable:

my $regex = do { my @escaped; push @escaped, quotemeta for @filelist; my $joined = join '|', @escaped; qr/^(?:$joined)$/; };
or, if you like things done in 1 shot,
my $regex = '^(?:' . join('|', map quotemeta, @filelist) . ')$';
or, for the overly clever, my $regex = qr/^(?:@{[join '|', map quotemeta, @filelist]})$/;

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re^2: Search array of file names in directory structure
Select or Download Code
Re^3: Search array of file names in directory structure
by Kenosis (Priest) on Oct 01, 2012 at 18:56 UTC

    Great comments! Actually, I completely missed the l? in the original regex. Unless I'm mistaken, your regex filter also doesn't allow for checking .htm files.

    Have updated my posting. Appreciate you bringing these issues to my attention.

      It doesn't, but only insofar is it only checks the literals of the passed list. At some point, of course, all this becomes academic, since we don't actually know the entire use case; TIMTOWTDI.


      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        Thanks, kennethk. I appreciate your insights about this...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996698]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (14)
As of 2014-07-31 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (249 votes), past polls