Merging Arrays
Because an array is just a comma-separated sequence of values, you can combine them together as shown below:#! /usr/bin/perl
@numbers = (1,3,(4,5,6));
print "numbers = @numbers\n";This will produce following result:
numbers = 1 3 4 5 6
The embedded arrays just become part of the main array as shown below:#!/usr/bin/perl
@odd = (1,3,5);
@even = (2, 4, 6);
@numbers = (@odd, @even);
print "numbers = @numbers\n";This will produce following result:
numbers = 1 3 5 2 4 6
No comments:
Post a Comment