To split an array in Perl, you can use array slicing to create new arrays representing the split parts.
In this example,
@numbers
with integer elements.@numbers
into new arrays.@numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9);
@slice1 = @numbers[0..2];
@slice2 = @numbers[3..5];
@slice3 = @numbers[6..8];
print join(', ', @slice1) . ' | ' . join(', ', @slice2) . ' | ' . join(', ', @slice3);
1, 2, 3 | 4, 5, 6 | 7, 8, 9
In this tutorial, we learned How to Split an Array in Perl language with well detailed examples.