Thanks, works great.

"Tassilo Von Parseval" <[EMAIL PROTECTED]> wrote in
message news:[EMAIL PROTECTED]
> On Fri, May 23, 2003 at 01:36:11PM -0400 Moshe wrote:
>
> > I have a program that lets the user define the regexp pattern as well as
set
> > option like /g, /i, /m, and /s
> >
> > What I want to be able to do is construct the loop condition based on
the
> > user's selected options:
> >
> > so the loop condition may be any of the following
> >
> > while ($source =~ /$pattern/og) {...}
> >
> > while ($source =~ /$pattern/oi) {...}
> >
> > while ($source =~ /$pattern/ogi) {...}
> >
> > while ($source =~ /$pattern/ogs) {...}
> >
> > while ($source =~ /$pattern/ogm) {...}
> >
> > You get the idea. I don't want to create a separate loop for each
> > possibility.
> > I want to build it as a string then "execute" it.
> >
> > What Are my options?
>
> If you want to build it as a string and execute it, string-eval might in
> fact be the only solution (with all the implied problems if this eval is
> going to happen in sensitive context like CGI or so).
>
> There is however a way to make these match-modifiers part of the
> pattern:
>
>     /abc/i;
>
>     # can also be written as
>
>     /(?i)abc/;
>
> The m, s, x, i modifiers can all thusly be handled. g and o are
> different but you can probably assume that g should always be used when
> the pattern is used as the condition for a while-loop. So when you have
> the modifiers and the pattern in two variables @modifiers and $pattern,
> you can create the regex and while-condition like this:
>
>     my $rex = do {
>         local $";   # thus no need for an awkward join()
>                     # also only effective within the do-block
>         "([EMAIL PROTECTED])$pattern";
>     };
>     while ($source =~ /$rex/og) {
>         ...
>     }
>
> Tassilo
> --
>
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
>
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
>
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to