Programming Tips - perl: How do I delete an element from a perl array?

Date: 2009jul4 Update: 2025sep2 Language: perl Q. perl: How do I delete an element from a perl array? A. To delete element $i from array @a use splice() like this:
splice(@a, $i, 1);
This will decrement the number of elements in your array by 1. There is also a "delete" command in perl but it does not do quite this. Note that splice() works in-place. So do NOT assign the return to your array like this:
@a = splice(@a, $i, 1); # WRONG, WRONG, WRONG