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

Re: $*ARGFILES and MAIN

Thread Previous | Thread Next
From:
yary
Date:
September 23, 2019 19:09
Subject:
Re: $*ARGFILES and MAIN
Message ID:
CAG2CFAZphXrdxvAQq-oS_7wm=xJbkTRMdmJAYEngZHk4Qd036g@mail.gmail.com
for optional options like -H, use "multi sub main" - then you can have
different sets of options available without having to fiddle with *@rest

-y


On Mon, Sep 23, 2019 at 2:20 PM Elizabeth Mattijsen <liz@dijkmat.nl> wrote:

> > On 23 Sep 2019, at 19:53, Marc Chantreux <eiro@phear.org> wrote:
> >  multi sub MAIN ( :$l ) { say +lines }
> >  multi sub MAIN ( :$c ) { say [+] lines>>.chars }
>
> Isn't that just `slurp.chars` ?
>
> >  multi sub MAIN ( :$w ) { say [+] lines.map: +*.words }
>
> Isn't that just `+words` ?
>
>
> > now i want grep that can have both -H (head the line with the filename)
> > and the -n (add the number of the line). my 'almost working' attempt was
> > but it takes the flags as signatures.
> >
> >  sub MAIN ( Str $pattern, :$H = False , :$n = False , *@rest ) {
> >    (IO::ArgFiles.new: @rest).lines>>.say
> >  }
>
> You should **never** use >>. on anything that you expect the order of
> execution to be the order of the input.  `>>.` allows the compiler to
> execute the code over multiple threads, so the `say` could be shown out of
> order.
>
>
> Liz

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