Re: accepting values on the command line

2017-07-01 Thread Gabor Szabo
On Sat, Jul 1, 2017 at 4:30 PM, Elizabeth Mattijsen  wrote:
>
>> On 1 Jul 2017, at 15:15, Gabor Szabo  wrote:
>>
>> I was hoping to wrote a simple script that would accept a bunch of
>> filenames on the command line so I wrote:
>>
>> #!/usr/bin/env perl6
>> use v6;
>>
>> multi sub MAIN(@files) {
>>say @files.perl;
>> }
>
> This signature will only accept an Iterable.  The command line parameters are 
> *not* considered a list, so this will not match.  What you need is a slurpy 
> array:
>
> multi sub MAIN(*@files) {
> say @files.perl;
> }
>
>
> $ 6 'sub MAIN(*@a) { dd @a }' a b c d
> ["a", "b", "c", "d"]
>

thanks
Gabor


Re: accepting values on the command line

2017-07-01 Thread Elizabeth Mattijsen

> On 1 Jul 2017, at 15:15, Gabor Szabo  wrote:
> 
> I was hoping to wrote a simple script that would accept a bunch of
> filenames on the command line so I wrote:
> 
> #!/usr/bin/env perl6
> use v6;
> 
> multi sub MAIN(@files) {
>say @files.perl;
> }

This signature will only accept an Iterable.  The command line parameters are 
*not* considered a list, so this will not match.  What you need is a slurpy 
array:

multi sub MAIN(*@files) {
say @files.perl;
}


$ 6 'sub MAIN(*@a) { dd @a }' a b c d
["a", "b", "c", "d"]


Liz

accepting values on the command line

2017-07-01 Thread Gabor Szabo
I was hoping to wrote a simple script that would accept a bunch of
filenames on the command line so I wrote:


#!/usr/bin/env perl6
use v6;

multi sub MAIN(@files) {
say @files.perl;
}



$ perl6 code.pl6
Usage:
  code.pl6 

$ perl6 code.pl6 abc
Usage:
  code.pl6 

$ perl6 code.pl6 abc def
Usage:
  code.pl6 

I got desperate, but that did not help either:
$ perl6 code.pl6 --files abc
Usage:
  code.pl6 


I am rather confused by this.


$ perl6 -v
This is Rakudo version 2017.06 built on MoarVM version 2017.06
implementing Perl 6.c.


Gabor