Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

is it possible in some way to supply variable flags to the match m// operator? - example :
my $flags = 'i'; my $string = "this is a tEst"; if ( $string =~ m/text/$flags ) { print "this worked\n"; }
so far i'm finding that perl doesn't like it (syntax error style of dislike) - i'm having a hard time finding any official word from the docs or other sources as to whether or not this is specifically not possible or some alternate way of performing the same. any help appreciated!

Replies are listed 'Best First'.
Re: variable flags to match operator?
by Fletch (Bishop) on Sep 14, 2003 at 21:32 UTC

    You probably want to use the embedded form (?ismx:foo), which you could whip up on the fly using the qr// operator. Search for `imsx-imsx:pattern' in perldoc perlre for more info.

Re: variable flags to match operator?
by gjb (Vicar) on Sep 14, 2003 at 21:34 UTC

    Have a look at the docs on extended patterns. Using embedded pattern modifiers will do the trick.

    Hope this helps, -gjb-

Re: variable flags to match operator?
by Anonymous Monk on Sep 14, 2003 at 21:45 UTC
    you guys rule :) .. thanks! - worked like a charm