Timo, perl6-users,

I don't want to print out the WHOLE text resulting from the match (in my
case a long file,) but just the /replacement/ string.

I'm sticking with syntax such as (which is also - for me - readable)

$layn ~~ s:g
    / (\W) [[RMA\.]? OpenNURBS\.]? I? On (<[2..4]>) dPoint
/{""if++$n;$r=
    "$0Rhino.Geometry.Point$1d"
}/; say "$r $n $/" if $/;

[note that $r only appears once in the rule but both defines and effects
the replacement,  and that    {""if++$n;   counts the replacements due to
:g   ].

Still it would be more straightforward to have something like
     $layn ~~ s:g/ (\W) [[RMA\.]? OpenNURBS\.]? I? On (<[2..4]>) dPoint
/$0Rhino.Geometry.Point$1d/;
and have a more perl6-built-in way of getting hold of the /replacement/ and
the count.

Peter Schwenn

On Thu, May 22, 2014 at 9:58 PM, <perl6-users@perl.org> wrote:

>  [ Sorry for not replying to the whole list earlier, I hope all readers
> will be able to cope with fishing my reply out of the full-quotes. ]
>
> Peter,
>
> Here's what I came up with using the assignment variant of the
> substitution operator:
>
> > perl6-m -e 'my $text = "Well, hello!"; $text ~~ s[ <alpha>+(\W) ] = my
> $res = "Rhino$0"; say (:$res); say (:$text)'
> > "res" => "Rhino,"
> > "text" => "Rhino, hello!"
>
> Hope to help!
>   - Timo
>
>
>

Reply via email to