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 <l...@dijkmat.nl> wrote: > > On 23 Sep 2019, at 19:53, Marc Chantreux <e...@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