develooper Front page | perl.perl6.users | Postings from June 2019

Re: replace s///r ?

Thread Previous | Thread Next
From:
Brad Gilbert
Date:
June 11, 2019 13:26
Subject:
Re: replace s///r ?
Message ID:
CAD2L-T0NXM=7JOoo0my-VDgjExMAUSPkwUe_Y3_0MnV_Z5oUDw@mail.gmail.com
The /r modifier on s/// in Perl5 is S/// in Perl6.

Though you have to put it into a block lambda, otherwise it applies to
$_ before it gets a chance to be passed to map.

    $*ARGFILES
     . lines
     . grep( / ^ <digit>+ $ / )
     .  map( {S/^/ * /} )
     .  map(&other-things-to-do)
     .  map(&say)

On Mon, Jun 10, 2019 at 11:19 PM Marc Chantreux
<marc.chantreux@renater.fr> wrote:
>
> hello people,
>
> in perl5, i can
>
>         print for
>             map  s/^/4/r,
>             grep /^\d+$/,
>             <ARGV>
>
> the perl6 version is a Seq, so much more memory friendly
> but i expected (and haven't found in the documentation)
> a short equivalent of s///r so the shorter i have is:
>
>     $*ARGFILES
>      . lines
>      . grep( / ^ <digit>+ $ / )
>      .  map( *.subst(/^/," * ") )
>      .  map(&other-things-to-do)
>      .  map(&say)
>
> when, of course, i want to replace
>
>      .  map( *.subst(/^/," * ") )
>
> by something like
>
>      .  map( s:r/^/* / )
>
> any idea?
>
> regards
> marc

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