To join arrays in Perl, you can use the push function or concatenate arrays using the dot operator (.)
In this example,
@arr1
and @arr2
.push
function to add elements of @arr2
to @arr1
.@arr1
containing elements from both arrays.@arr1 = (1, 2, 3);
@arr2 = (4, 5, 6);
push(@arr1, @arr2);
print "Joined Array: @arr1\n";
Joined Array: 1 2 3 4 5 6
In this example,
@arr1
and @arr2
.@arr2
to @arr1
using the dot operator (.)@arr1
containing elements from both arrays.@arr1 = (1, 2, 3);
@arr2 = (4, 5, 6);
@result = (@arr1, @arr2);
print "Joined Array: @result\n";
Joined Array: 1 2 3 4 5 6
In this tutorial, we learned How to Join Arrays in Perl language with well detailed examples.