Hello,

In the past few days I've been converting some "incremental parsing"-regex
code from perl 5 to perl 6 (I haven't not touched grammars, yet...)

In Perl 5 I often used the /g and /c modifiers so that the following
snippet of code doesn't die:

    # perl5

    my $test = "      foo bar";

    die unless $test =~ /^\s+/g;
    die unless $test =~ /\Gfoo\s+/g;
    die if     $test =~ /\Gwillnotmatch/gc; # ...what is the equivalent of
the 'c' modifier in Perl 6?
    die unless $test =~ /\Gbar/g;

    say pos $test; # yields "13"

I managed to translate such code in Perl 6, by using the "m:p/.../" regex,

When I anticipate an unsuccessful match then I must temporarily store $/.pos
and provide it to the next regex (e.g. "m:p($P)//"), so it seems,

That works.... but it riddles my current solutions with "$P = $/.pos;"
assignments.

Is there a way to retain this match like in Perl 5?

Is there a better way in general?

... perhaps it's time to look into grammars? ;)

Thanks!

Regards,

Raymond Dresens.

Reply via email to