On 03/19/2015 04:05 PM, Tom Browder wrote:
In Perl 5 I can do this:

my @a = (1, 2);
my @b = (3);

foo(@a,@b);

sub foo { my $n = @_;  die "Wrong num args: $n" if ($n != 3);}

In Perl 6 I think this is correct (or nearly so):

sub foo(*@args) { die "Wrong num args: { @args.elems }" if @args.elems != 3;}

Questions for Perl 6:

foo is now defined as:

sub foo($a, $b, $c) { # do something with $a, $b, $c }

but I want to call it with a flattened array arg.

1.  How can I combine arrays @a and @b into one array?

generally with the comma operator:

my @combined = @a, @b;

2.  Can I flatten the arrays into elements inside the foo call?

foo(|@combined)

Cheers,
Moritz

Reply via email to