Is there an easy way to remove n consecutive elements of a Perl array (thus making it shorter in length)?
You are looking for the Perl builtin function splice, which lets you pick a starting point, number of elements to remove, and an optional replacement list.
my @array = 0 .. 9;
my @slice = splice @array, 3, 3;
say "@slice"; # prints "3 4 5"
say "@array"; # prints "0 1 2 6 7 8 9"
say 0 + @array; # prints 7
You can use splice to remove array elements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With