Erik: Funktionen aus reg. Ausdrücken Aufrufen?

Hi,
ist es möglich aus einem regulären Aufruf (z.B. beim Ersetzen mit "$1") eine Funktion aufzurufen? Habe allerlei versucht und ich beginne mich zu fragen ob es überhaupt mögich ist.
MfG
Erik

  1. use Mosche;

    ist es möglich aus einem regulären Aufruf (z.B. beim Ersetzen mit "$1") eine Funktion aufzurufen? Habe allerlei versucht und ich beginne mich zu fragen ob es überhaupt mögich ist.

    probier es mal mit dem Modifier 'e', das heisst s///e. 'e' bewirkt, dass der Ausdruck evaluiert (ausgewertet) wird. Damit sollte es funktionieren.

    use Tschoe qw(Matti);

    1. probier es mal mit dem Modifier 'e', das heisst s///e. 'e' bewirkt, dass der Ausdruck evaluiert (ausgewertet) wird. Damit sollte es funktionieren.

      Danke, funktioniert.
      VG
      Erik

      1. hallo Erik

        noch nachgelegt:

        perldoc perlretut

        Dort steht u.a.:

        A bit of magic: executing Perl code in a regular expression
        Normally, regexps are a part of Perl expressions. Code evaluation  expressions turn that around by allowing arbitrary Perl code to be a part of of a regexp. A code evaluation expression is denoted (?{code}), with code a string of Perl statements.

        Code expressions are zero-width assertions, and the value they return depends on their environment. There are two possibilities: either the code expression is used as a conditional in a conditional expression (?(condition)...), or it is not. If the code expression is a conditional, the code is evaluated and the result (i.e., the result of the last statement) is used to determine truth or falsehood. If the code expression is not used as a conditional, the assertion always evaluates true and the result is put into the special variable $^R. The variable $^R can then be used in code expressions later in the regexp. Here are some silly examples:

        $x = "abcdef";
            $x =~ /abc(?{print "Hi Mom!";})def/; # matches,
                                                 # prints 'Hi Mom!'

        u.s.w.