On Sat, Jul 09, 2005 at 06:01:20AM +0300, Yuval Kogman wrote:
> How trivial is it to add a ?<{ } block that is executed with the
> same semantics as ?{ }, except that instead of running when the
> engine matches over it, it gets run as the engine backtracks over
> it?
> 
> my $thing = qr/
>       ?{ do_something() }
>       ?<{ undo_it() }
>       $try_this_pattern
> /x;
> 
> if $try_this_pattern fails, undo_it() is called to undo
> do_something().

The trivial way:

    my $thing = qr/
        (?{ $obj = create() }
        $try_this_pattern
    /x;

    sub create  { do_something(); bless [] }
    sub DESTROY { undo_it() }

I don't think you'll have to look to hard to find problems with this
approach but most of them will be related to the predictability
of backtracking (due to optimizations, unspecified implementation, etc).
Any addition to the RE engine would likely suffer from the same lack of
predictability so would probably not be much of an improvement over the
above code.

-- 
Rick Delaney
[EMAIL PROTECTED]

Reply via email to