K@rl: Funktionen aus reg. Ausdrücken Aufrufen?

Beitrag lesen

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.