in reply to save regex in a file?

If you really want to put the m and the delimiter in the file, you will have to remove them before applying the regex. Something like this:
$re =~ s/^m//; $re =~ s/^.//; $re =~ s/.$/; $string =~ $re;
Note that this may not give the same behavior as a normal match if you've used a delimiter that also appears in the regex, e.g. m|foo\|bar|

Replies are listed 'Best First'.
Re: Re: save regex in a file?
by smackdab (Pilgrim) on Oct 16, 2001 at 09:06 UTC
    It is a bummer to hear that. It really seems like a big disadvantage to not be able to specify the delimiter in the file as I know there are "special" delimiters that are sometimes used. It also means that I have to separately ask if there are any operators "ie: case insensitive" as an example...m/abc/i

    Would eval() help? I tried the simple case I could think of and it didn't seem to work...

    Thanks for ideas!!!
      Using eval would just introduces a whole new bag of worms; I don't think it would be the best solution. Fortunately, you can specify the modifiers within the regex. Here are two quick examples.
      (?i)abc (?s-m:^start.*end)
      The first turns on case-insensitivity for the entire pattern. The seconds turn on single-line matching and turns off multi-line matching for the part of the pattern within the parentheses.

      perlre explains this syntax in more detail.