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

Re: $*ARGFILES and MAIN

Thread Previous | Thread Next
From:
Elizabeth Mattijsen
Date:
September 23, 2019 18:20
Subject:
Re: $*ARGFILES and MAIN
Message ID:
611AAB8D-6BFD-43D4-AE3B-C23F45636D1C@dijkmat.nl
> 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