by Jeremy Canfield | Updated August 1st, 2018
Let's say you have an array of fruit that contains apple, banana, orange, and grape.
@fruits = qw(apple banana orange grapes);
Splice can be used to remove a value from the array. In this example, every occurence of "grape" will be removed from @fruits.
# Count the number of values in the array $count = scalar @fruits; # Set the index to zero $index = 0; # Find every occurence of the value that you want to remove from the array $index++ until $fruits[$index] eq 'grape' or $index == $count; # Remove every occurence from the array splice (@fruits, $index, 1);