develooper Front page | perl.perl5.porters | Postings from April 2007

Re: Proposed changes and to regular expression interfaces in core

Thread Previous | Thread Next
From:
Ævar Arnfjörð Bjarmason
Date:
April 3, 2007 06:25
Subject:
Re: Proposed changes and to regular expression interfaces in core
Message ID:
51dd1af80704030625w77be3fa6nbefda5b45dda6fcc@mail.gmail.com
On 4/2/07, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Here are some further examples of what I want to do, the following
example works now in re::engine::Plugin (not the one on cpan atm
though):

use re::engine::Plugin (
    exec => sub {
        my ($re, $sv) = @_;

        $re->captures( sub {
            # Return a closure which alters the $sv
            sub { $$sv = shift };
         } );

        1: # successful match
    }
);

my $str = "eek";

if (\$str =~ /rw: blah blah/) {
    $1->( "ook" );
    # $$str is now "ook" not "eek"
}

Doing C< $1->( "ook" ) > instead of C< $1 = "ook"  > is a bit hackish
though, so I'm going to propese something that'll make the baby dmq
cry. Implement numbered captures ($1 ... ) as a tied SCALAR and %+ and
%- as a tied HASH. This'll allow a smooth implementation of the p6 :rw
modifier as well as some things I haven't thought of / mentioned yet.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About