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

Re: replace s///r ?

Thread Previous | Thread Next
From:
William Michels via perl6-users
Date:
June 12, 2019 20:17
Subject:
Re: replace s///r ?
Message ID:
CAA99HCwKt0md1ahYRx4Ai7t_6k=_A4k-3n-SVZMPMVv7J5WChw@mail.gmail.com
Thank you Yary. It's not often I have to prepend a "4" to a mixed list
items of containing numbers, but your code is perfect for extracting
the numbers and prepending a dollar sign ($):

>  .say for (325, '44a', 555, 6).grep(/^\d+$/).map( '$' ~ * )
$325
$555
$6

Best Regards,

Bill.



On Mon, Jun 10, 2019 at 11:02 PM yary <not.com@gmail.com> wrote:
>
> Or if you need to "map" the substitution
>
> .say for (325, '44a', 555, 6).grep(/^\d+$/).map( *.subst(/^/,4) )
>
>
> -y
>
> On Mon, Jun 10, 2019 at 10:54 PM yary <not.com@gmail.com> wrote:
> >
> > p6 can transliterate from p5 rather literally
> >
> > say .subst(/^/,4) for grep /^\d+$/, (325, '44a', 555, 6);
> >
> >
> >
> > -y
> >
> > -y
> >
> >
> > On Mon, Jun 10, 2019 at 9: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