- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Merging Arrays in Perl
Because an array in Perl is just a comma-separated sequence of values, you can combine them together as shown below −
Example
#!/usr/bin/perl @numbers = (1,3,(4,5,6)); print "numbers = @numbers\n";
Output
This will produce the following result −
numbers = 1 3 4 5 6
The embedded arrays just become a part of the main array as shown below −
Example
#!/usr/bin/perl @odd = (1,3,5); @even = (2, 4, 6); @numbers = (@odd, @even); print "numbers = @numbers\n";
Output
This will produce the following result −
numbers = 1 3 5 2 4 6
- Related Articles
- Merging and rectifying arrays in JavaScript
- Alternatively merging two arrays - JavaScript
- Merging sorted arrays together JavaScript
- Sorting Arrays in Perl
- Merging two unsorted arrays in sorted order in C++.
- Merging two arrays in a unique way in JavaScript
- Perl Sequential Number Arrays
- Merging nested arrays to form 1-d array in JavaScript
- Transform Perl Strings into Arrays
- Transform Perl Arrays to Strings
- Merging elements of two different arrays alternatively in third array in C++.
- Merging two sorted arrays into one sorted array using JavaScript
- How to compare two arrays for equality in Perl?
- Quickly merging two sorted arrays using std::merge() in C++ STL(cute ho ap)
- Merging subarrays in JavaScript

Advertisements