4.9. Appending One Array to AnotherProblemYou want to join two arrays by appending all the elements of one to the end of the other. Discussion
The @ARRAY1 = (@ARRAY1, @ARRAY2);
Here's an example of @members = ("Time", "Flies"); @initiates = ("An", "Arrow"); push(@members, @initiates); # @members is now ("Time", "Flies", "An", "Arrow")
If you want to insert the elements of one array into the middle of another, use the splice(@members, 2, 0, "Like", @initiates); print "@members\n"; splice(@members, 0, 1, "Fruit"); splice(@members, -2, 2, "A", "Banana"); print "@members\n"; This is output:
See Also
The Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|