Re: list named argument in MAIN

2017-06-01 Thread Marcel Timmerman

On 06/01/2017 03:03 PM, H.Merijn Brand wrote:

On Thu, 1 Jun 2017 14:11:47 +0200, Timo Paulssen 
wrote:


It seems like this only works if you supply --dirs= multiple times

 perl6 -e 'sub MAIN (List :$dirs=[]) { .say for @$dirs }' --dirs=d1 
--dirs=d2 --dirs=d3

 d1
 d2
 d3

took me a bit as it needs both .List *and* flat. Got help on IRC

$ perl6 -e 'sub MAIN (List :$dirs=[]) { .say for flat @$dirs.List».split: /","/ 
}' --dirs=d1 --dirs=d2 --dirs=d3,d4,d5
d1
d2
d3
d4
d5



Re: list named argument in MAIN

2017-06-01 Thread H.Merijn Brand
On Thu, 1 Jun 2017 14:11:47 +0200, Timo Paulssen 
wrote:

> It seems like this only works if you supply --dirs= multiple times
> 
> perl6 -e 'sub MAIN (List :$dirs=[]) { .say for @$dirs }' --dirs=d1 
> --dirs=d2 --dirs=d3
> 
> d1
> d2
> d3

took me a bit as it needs both .List *and* flat. Got help on IRC

$ perl6 -e 'sub MAIN (List :$dirs=[]) { .say for flat @$dirs.List».split: /","/ 
}' --dirs=d1 --dirs=d2 --dirs=d3,d4,d5
d1
d2
d3
d4
d5

-- 
H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.25   porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/http://www.test-smoke.org/
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/


pgpyPZkVLd0DX.pgp
Description: OpenPGP digital signature


Re: list named argument in MAIN

2017-06-01 Thread Marcel Timmerman

On 06/01/2017 02:11 PM, Timo Paulssen wrote:

It seems like this only works if you supply --dirs= multiple times

 perl6 -e 'sub MAIN (List :$dirs=[]) { .say for @$dirs }' --dirs=d1
--dirs=d2 --dirs=d3

 d1
 d2
 d3

HTH
   - Timo


Thanks Timo,

Just tested this and it works. But there is still a problem and maybe a 
bug. It should accept a single option to have a list with one item. In 
that case it shows the usage message.


FWIW, I've cooked up a short piece to have it my way


my @a;
for @*ARGS -> $a {
  if $a ~~ m/^ '--dirs'/ {
for $a.split('=')[1].split(',') -> $d {
  @a.push("--dirs=$d");
}
  }

  else {
@a.push($a);
  }
}
@*ARGS = @a;


sub MAIN (List :$dirs=[]) { }

Regards


Re: list named argument in MAIN

2017-06-01 Thread Timo Paulssen
It seems like this only works if you supply --dirs= multiple times

perl6 -e 'sub MAIN (List :$dirs=[]) { .say for @$dirs }' --dirs=d1
--dirs=d2 --dirs=d3

d1
d2
d3

HTH
  - Timo