Hi vr,
my $regex = qr{(??{ join '|', map {quotemeta} qw/. | %/ })};
Another excellent idea, thank you! I've updated my root node.
it's eval'ed "before parsing a regex", while s///e is not about it at all
Yes, you're right, it was misleading of me to write that qr//e would be "analogous to s///e", since in s///e it's the replacement part that gets evaled, not the regex.
Update: Your solution has the interesting feature that the code gets reevaluated every time:
use Test::More;
my @values = qw/abc def/;
my $re = qr{^(??{ join '|', map {quotemeta} @values })$}i;
like 'ABC', $re;
like 'DEF', $re;
unlike 'GHI', $re;
push @values, 'ghi';
like 'ABC', $re;
like 'DEF', $re;
like 'GHI', $re;
done_testing;
Thanks, -- Hauke D
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|