2

I have created a simple multi-dimensional array:

my @arraytest = ([1, 2, 3],[4, 5, 6],[7, 8, 9]);
print "Array - @$_\n" for @arraytest;

Output:

Array - 1 2 3 
Array - 4 5 6 
Array - 7 8 9

How do I push "10, 11, 12" to the next element in this array?

1 Answer 1

9

You need to create an array reference, and push that as the next element. The easiest way is to make an anonymous array ref.

push @arraytest, [10, 11, 12];

Your output now looks like this:

Array - 1 2 3
Array - 4 5 6
Array - 7 8 9
Array - 10 11 12

The important part is that your @arraytest is an actual array (not a reference), so you can just operate on it directly with push, pop and so on.

See perllol for more details.

Sign up to request clarification or add additional context in comments.

1 Comment

The question could also read as push that string, then the answer would be push @arraytest, "10, 11, 12";.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.