note
kennethk
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 <c>.htm</c> files, as in the original regex. Simpler and more recyclable:
<c>my $regex = do {
my @escaped;
push @escaped, quotemeta for @filelist;
my $joined = join '|', @escaped;
qr/^(?:$joined)$/;
};</c>
or, if you like things done in 1 shot,
<c>
my $regex = '^(?:' . join('|', map quotemeta, @filelist) . ')$';
</c>
or, for the overly clever,
<c>my $regex = qr/^(?:@{[join '|', map quotemeta, @filelist]})$/;</c>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-712372">
<hr />
<p>#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.</p>
</div></div>
996672
996682