in reply to reversing a compiled regex?

I suppose you could do negative lookahead, but that seems to be overkill. Better, I think, would be to modify your interface so that your caller can indicate what regex he/she wants as well as if this is a postive or negative match. Then, you just use =~ or !~, as appropriate.

One way to do this while still hiding the operation is to expand your data structure. Instead of one level, go to two levels.

my %rx = ( equals => [ qr/^\Q$sv\E$/i, 1 ], 'not equals' => [ qr/^\Q$sv\E$/i, 0 ],
The 1 meaning use =~, the 0 meaning use !~.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: reversing a compiled regex?
by dash2 (Hermit) on Mar 27, 2003 at 12:34 UTC
    The solution I did indeed use in the end. I think your sig is relevant here ;-)

    Well, almost. Actually I just gave "equals" and "not equals" (et cetera) the same keys in the regex and then did roughly:

    if ($key =~ /not/) { return $string !~ /$rx/; } else { return $string =~ /$rx/; }

    andramoiennepemousapolutropon

      *grins* If it's all you need, then it's all you need. :-)

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.