Appending multiple values to an array in Perl6

  • A+
Category:Languages

I am looking for a way to append multiple values to an @array. The documentation points out that there is a method called .append that would do that job. but when I am doing something like this:

my @array = <a b>; my @values = 1,2,3; @array.append: @values, 17; 

I am getting a nested result:

[a b [1 2 3] 17] 


You need to slip the array as Perl 6 doesn't auto-slip ("flatten"), except if it's the only iterable in an a argument.

So:

@array.append: @values;      # will slip the array as it's the only parameter @array.append: @values,17;   # does not slip @values @array.append: |@values, 17; # will slip the @values into @array 

Instead of |@values, you could also slip(@values) or @values.Slip.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: