in reply to Regular Expression Question

perlre explains why this is not permitted, and how to make it permitted if you really want to do it...

$string =~ /$re/;

Before Perl knew how to execute interpolated
code within a pattern, this operation was com­
pletely safe from a security point of view,
although it could raise an exception from an
illegal pattern.  If you turn on the "use re
'eval'", though, it is no longer secure, so you
should only do so if you are also using taint
checking.  Better yet, use the carefully con­
strained evaluation within a Safe module.  See
perlsec for details about both these mechanisms.

We're not surrounded, we're in a target-rich environment!

Replies are listed 'Best First'.
Re: Re: Regular Expression Question
by grantm (Parson) on Apr 03, 2003 at 18:39 UTC
    perlre explains why this is not permitted

    Actually, perlre explains why (?{ code }) is not permitted which is quite a different thing.

    The original code worked exactly as expected for me with the addition of a closing ')' on the if statement. (The match fails to increment $yep because the 'v' in $word doesn't match the vowel pattern).

    Using variable interpolation in a regex is not a 'weird idea' at all. It can be an excellent way to improve the readability of your code.

Re: Regular Expression Question
by Abigail-II (Bishop) on Apr 03, 2003 at 18:35 UTC
    I don't get your answer. What does it have to do with the question?

    Abigail