On 10/5/18 6:09 PM, Brandon Allbery wrote:
That's where the | comes in. If you say
my @b = (1, |@a, 2);
then you get (1, 'a', 'b', 'c', 2) like in Perl 5. But you can specify
what gets flattened, so you can choose to flatten some arrays but not
others if you need to for some reason:
my @b = (1, |@b, 2, @b, 3);
gives you (1, 'a', 'b', 'c', 2, ('a', 'b', 'c'), 3). This often matters
in parameter lists, if you want one of the parameters to be the list
itself instead of it being spread across multiple parameters. In Perl 5
you had to say \@b to pass a ref to the list instead, and the sub had to
know it was getting a scalar containing an arrayref and needed to
dereference it (if you don't know, don't ask; it's ugly).
Am I correct in my assumption?
A little off the question, but how do I address something
inside a nested array?
In the following, how do I get at the "b"
$ p6 'my @x=<a b c>; my @y=<1 2 @x 3 4>; say @y; dd @y;'
[1 2 @x 3 4]
Array @y = [IntStr.new(1, "1"), IntStr.new(2, "2"), "\@x", IntStr.new(3,
"3"), IntStr.new(4, "4")]
Also, how do I flatten @y above?
Thank you for the help!
-T