On Tue, 14 Mar 2006 09:14:09 -0700
Bryan Scott <[EMAIL PROTECTED]> wrote:

> I disabled warnings to avoid filling my logs with pattern matching 
> errors. If others have suggestions as to the safe perl mechanisms for
> proper pattern matching from values in a file, let me know.
Safe depends on trusting the one who writes the files :) For me it's
just me and sometimes my co-worker, not a user, so the eval() should be
ok.

I'm currently using something like the following in one of my plugins.
It will log a warning message if the regexp is fsck'd up. If you're
annoyed, just don't log or lower the log level:

    my ($ok, $err, $re, $const, $comment);
    foreach ($self->qp->config("rcpt_regexp")) {
        s/^\s*//;
        ($re, $const, $comment) = split /\s+/, $_, 3;
        if ($re =~ m#^/(.*)/$#) {
            $re = $1;
            $ok = eval { $re = qr/$re/i; };
            # next if $@;
            if ($@) {
                ($err = $@) =~ s/\s*at \S+ line \d+\.\s*$//;
                $self->log(LOGWARN, "REGEXP '$re' not valid: $err");
                next;
            }
            $re = $ok;
        }
        # ... snip...
        $ok    = $const;
        $const = Qpsmtpd::Constants::return_code($const); 
        unless (defined $const) {
            $self->log(LOGWARN, "'$ok' is not a valid "
                         . "constant, ignoring this line");
            next;
        }
        # ...snip ...
        next unless $rcpt =~ $re;
        $self->log(LOGDEBUG, "RE $re matched $rcpt, returning $ok");
        return ($const, $comment);
    }

Hanno

Reply via email to