in reply to regex problem

Well, there are two differences between your examples -- the use of variables and the switch from !~ to =~. Is the latter a typo? If not, then you can accomplish the same thing by using [^$pattern]. In any case, your real question is whether regexes can be constructed, and the answer is yes. It's simply a matter of writing it as a normal string, and using perlfunc:eval to compile at runtime. (Note, you may have to do some character escaping (using '\') in your original string if it gets at all complicated.) For example: my $string = "$foo|$bar"; for ( list ) { eval !~ /$string/; }

As far as expense goes, I can't see any reason why this would be particularly taxing.

Update Juerd++ for the correction regarding [^$pattern]. My mistake.

Replies are listed 'Best First'.
Re: Re: regex problem
by Juerd (Abbot) on Feb 09, 2002 at 21:49 UTC

    If not, then you can accomplish the same thing by using [^$pattern].

    [^$pattern] is misleading. [] create a character class, so [^$characters] would be a good example. That doesn't negate a regex, though.

    It's simply a matter of writing it as a normal string, and using perlfunc:eval to compile at runtime.

    That requires parsing. Parsing is bad, because it's too easy to do it the wrong way. This too doesn't really answer the question.

    eval !~ /$string/;

    Unless you meant eval($_) !~ /$string/;, and I'm sure you didn't, that's wrong.

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$