Array slicing allows a user to retrieve more than one element of an array at once.
For Example :
@myarray = (1,2,3,4,5);
@subarray = @myarray [0,1];
Print (“@subarray\n”);
Output : 1 2
Thus we can ‘Slice’ the existing array and retrieve its elements.
We can also slice an array into large slices using the “List-range operator” of Perl. List-range operator allows us to specify a range which will return all the elements in that range.
Example:
@daysOfMonth = (1..31); #daysOfMonth will contain 1 to 31 elements.
@fortnight = @daysOfMonth[1..15];
This will assign a slice consisting of the first 15 elements to fortnight array.